如何更改ttk :: combobox的颜色

时间:2018-10-27 14:16:55

标签: tcl tk

我想更改ttk :: combobox小部件的颜色。这是我的代码:

set MyBackgroundColor #00FF00
set MyForegroundColor #FF0000
font create MyFont -family Helvetica -size 12 -slant roman -weight normal
ttk::style theme use default
ttk::style configure TCombobox -font MyFont -background $MyBackgroundColor -fieldbackground $MyBackgroundColor -foreground $MyForegroundColor
option add *ComboboxPopdown.f.l.font MyFont
option add *ComboboxPopdown.f.l.background $MyBackgroundColor
option add *ComboboxPopdown.f.l.foreground $MyForegroundColor
# option add *ComboboxPopdown.f.l.selectbackground $MyBackgroundColor
# option add *ComboboxPopdown.f.l.selectforeground $MyForegroundColor

set Liste {Anton Berta Caesar}
set MyVar [lindex $Liste 0]
ttk::combobox .cb -values $Liste -textvariable MyVar -font MyFont -background $MyBackgroundColor -foreground $MyForegroundColor
pack .cb

如果我打开组合框并将鼠标移到条目上,则会以黑色字体颜色和灰色背景色突出显示条目。可以更改这些颜色吗?

1 个答案:

答案 0 :(得分:1)

您可以使用以下选项更改弹出窗口的颜色:

option add *TCombobox*Listbox.background color
option add *TCombobox*Listbox.foreground color
option add *TCombobox*Listbox.selectBackground color
option add *TCombobox*Listbox.selectForeground color

编辑:

如果您需要更改特定弹出窗口的颜色或更改 创建组合框后的颜色:

set popdown [ttk::combobox::PopdownWindow .combo]
$popdown.f.l configure -background color

参考:wiki: Changing Widget Colors