如何完全更改 Tkinter 列表框的顏色?
Tkinter Listbox 小部件對於以列表項的形式表示大量資料項非常有用。為了配置諸如更改整個 Listbox 的背景顏色之類的屬性,我們可以使用 configure(**options) 方法更改 Listbox 小部件的屬性。
示例
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add a Listbox widget with number as the list items
listbox =Listbox(win)
listbox.insert(END,"C++", "Java", "Python", "Rust", "GoLang", "Ruby", "JavScript", "C# ", "SQL", "Dart")
listbox.pack(side=LEFT, fill=BOTH)
listbox.configure(background="skyblue4", foreground="white", font=('Aerial 13'))
win.mainloop()輸出
執行以上程式碼將顯示一個自定義 Listbox 及其包含的一些列表項。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP