我发布了以下代码,创建一个简单的自定义背景和前景颜色样式ttk Combobox。

我在default和alt父主题测试了这个。

ttk combobox popdown listbox无法使用ttk style配置,也不能通过widget configure命令配置,可以使用option数据库配置listbox,了解更多信息这里

我使用的是Windows上的Python 3.7,Tcl/Tk 8.6。import tkinter as tk

from tkinter import ttk

window = tk.Tk()

style = ttk.Style()

# creating a custom theme

style.theme_create('custom_style',

parent='alt',

settings={'TCombobox':

{'configure':

{'selectforeground': 'blue',

'selectbackground': 'yellow',

'fieldforeground': 'blue',

'fieldbackground': 'yellow',

'background':'yellow'

}

}

}

)

style.theme_use('custom_style')

# following are style option for the drop down combobox listbox

window.option_add('*TCombobox*Listbox*Background', 'blue')

window.option_add('*TCombobox*Listbox*Foreground', 'yellow')

values = ['CS', 'EC', 'ME']

select_branch = ttk.Combobox(window, values=values, width=15, state='readonly')

select_branch.grid(row=0, column=0, padx=10, pady=10)

window.mainloop()

希望这能帮助你!

Logo

一站式 AI 云服务平台

更多推荐