简体   繁体   中英

How to change the color of the dropdown text color of ttk combobox widget?

First I was trying only used:

missed_list_combobox.config(foreground="red") 

Then I was trying to set new style:

style_missed_combobox = tkinter.ttk.Style()
style_missed_combobox.configure("Red.TCombobox", foreground="red")

And use it after create the combobox widget.

missed_list_combobox = tkinter.ttk.Combobox(frame4, state="readonly", width=32, style="Red.TCombobox")
missed_list_combobox.grid(row=2, column=3, padx=2, sticky="w", pady=3)

But same...it's only change the color of the top element in the combobox... not the entire dropdown elements... how can i change the color text of all the dropdown element..?

Thanks in advance, eliran

As far as I know this is not directly possible with tkinter because we cannot acccess the combobox's listbox through the python interface. However this can be done using the underlying tcl interpreter with:

missed_list_combobox.tk.eval('[ttk::combobox::PopdownWindow %s].f.l configure -foreground red' % missed_list_combobox)

If you also want to change the background to yellow, just add -background yellow to the above tcl command.

By the way, if you want to change the default foreground of all comboboxes' dropdown listbox, you can use

root.option_add('*TCombobox*Listbox.foreground' % frame, 'red')

but this will only apply to comboboxes created after this line ( root can be replaced by any widget)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM