[英]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.