所选组合框的背景色/默认值

2024-10-03 11:21:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望将tkinter组合框的默认白色更改为橙色,并在选择时将其更改为绿色。我找不到如何瞄准全场,我只能改变字体颜色。你知道吗

image1

我搜索了论坛和网络,但在任何地方都找不到解决方案。 我设法将Listbox的颜色设置为橙色,但没有设置默认值。你知道吗

image2

列表框背景

window.option_add("*TCombobox*Listbox*Background", 'orange')

我的组合框样式

ttk.Style().layout('combostyleO.TCombobox')
ttk.Style().configure('combostyleO.TCombobox', selectforeground='black', selectbackground='orange', background='green', foreground='orange', padding=4)

组合框创建

lendersR = StringVar(window)
lendersR.set('Select lender')  # set the default option
choicesR = excel.Excel().get_resi_lenders_from_csv()
choicesR = sorted(choicesR)
lenderMenuR = ttk.Combobox(window, width=55, height=30, font="Courier 10", textvariable=lendersR, values=choicesR, style="combostyleO.TCombobox")

Tags: style颜色tkinterwindow橙色optionttkset