[英]How to change the color of the active background of the dropdown menu (i.e. tk.Listbox) in a ttk.Combobox
以下代碼創建了一個ttk.Combobox小部件:
import tkinter.ttk as ttk
default_values = ['Peter','Scotty','Walter','Scott','Mary','Sarah','Jane',
'Oscar','Walley','Faith','Bill','Egor','Heley']
s=ttk.Style()
s.configure( 'TCombobox', font=('Purisa', 20, 'bold'), background ='cyan',
fieldbackground='pink')
c=ttk.Combobox(values=default_values)
c.master.option_add( '*TCombobox*Listbox.background', 'yellow')
c.master.option_add( '*TCombobox*Listbox.selectbackground','red') #does not work
c.master.option_add( '*TCombobox*Listbox.selectforeground','grey') #does not work
c.master.option_add( '*TCombobox*Listbox.highlightbackground','blue') # does not work
c.master.option_add( '*TCombobox*Listbox.highlightforeground','green') #does not work
c.master.option_add( '*TCombobox*Listbox.activestyle', 'underline') #does not work
c.grid()
單擊Combobox downarrow后,將顯示包含default values
的下拉菜單(即tk.Listbox
小部件)。 當鼠標懸停在下拉菜單上時,將出現鼠標指針下方的活動背景。 我想改變這個灰色活動背景的顏色。 我該怎么辦?
由於下拉菜單不是ttk小部件 ,因此它不會響應和ttk.Style()
設置。 我也嘗試過.option_add
方法,但只能更改Listbox背景。
您正在嘗試使用正確的選項來更改背景顏色:
c.master.option_add( '*TCombobox*Listbox.selectbackground','red')
但你犯了一個小錯誤,即selectbackground
。 在selectbackground
, background
的第一個字母應該是大寫。
*TCombobox*Listbox.selectbackground
變為*TCombobox*Listbox.selectBackground
-----------------------__^__-----------------------------------------__^__-------
嘗試:
c.master.option_add( '*TCombobox*Listbox.selectBackground','red')
同樣, foreground
變為Foreground
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.