Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change menu background color of Tkinter's OptionMenu widget?

If I take a simple example of OptionMenu from http://effbot.org/tkinterbook/optionmenu.htm, and add a line that sets background color (see below), only the button background changes color, not the drop-down menu which remains gray. Can I set color for both the button and the menu of OptionMenu?

I am using Windows 7, Python 2.6.6, Tkinter Rev 73770

from Tkinter import *  
master = Tk()  
variable = StringVar(master)  
variable.set("one") # default value  
w = OptionMenu(master, variable, "one", "two", "three")  
w.config(bg = "GREEN")  # Set background color to green  
w.pack()  
mainloop()  

Thank you

like image 920
Victor Avatar asked May 30 '11 15:05

Victor


1 Answers

You need to grab the menu object from the OptionMenu and set its background color. This should accomplish what you want...

w = OptionMenu(master, variable, "one", "two", "three")  
w.config(bg = "GREEN")  # Set background color to green

# Set this to what you want, I'm assuming "green"...
w["menu"].config(bg="GREEN")

w.pack()  
like image 120
Bryan Avatar answered Sep 30 '22 06:09

Bryan