Sun Bear
Sun Bear

Reputation: 8254

How to change the color of the active background of the dropdown menu (i.e. tk.Listbox) in a ttk.Combobox

The following code creates a ttk.Combobox widget:

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()

After clicking on the Combobox downarrow, a dropdown menu (which is a tk.Listbox widget) containing the default values will appear. When the mouse hovers over the dropdown menu, an active background below the mouse pointer will appear. I would like to change the color of this grey active background. How do I do so?

As the dropdown menu isn't a ttk widget, it will not respond to and ttk.Style() settings. I have also tried the .option_add method but only the Listbox background could be changed.

Issue: active background in dropdown menu

Upvotes: 4

Views: 1648

Answers (1)

Nouman
Nouman

Reputation: 7303

You are trying to use the correct option to make the background color change:

c.master.option_add( '*TCombobox*Listbox.selectbackground','red')

But you made a little mistake i.e. selectbackground. In selectbackground , the first letter of background should be capital.
*TCombobox*Listbox.selectbackground becomes *TCombobox*Listbox.selectBackground
-----------------------__^__-----------------------------------------__^__-------

Try:

c.master.option_add( '*TCombobox*Listbox.selectBackground','red')

Similarly , foreground becomes Foreground.

Upvotes: 2

Related Questions