Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit ttk style for ttk.OptionMenu

Recently started using ttk for improving my GUI looks, but i got stuck at editing ttk.OptionMenu style. As I uderstand code below should change background of all Radiobuttons and OptionMenus. For Radiobutton (and other elements I tried) it works just fine, but OptionMenu doesnt change at all.

s = ttk.Style()
s.configure("TRadiobutton", background="grey")
s.configure("TOptionMenu", background="grey")
like image 393
Radek Nevyhoštěný Avatar asked Dec 01 '25 09:12

Radek Nevyhoštěný


2 Answers

The style name for an OptionMenu is not TOptionMenu. For any widget the style name can get obtained using widget.winfo_class() and for an OptionMenu this returns TMenubutton.

So s.configure("TMenubutton", background="red") yields:

OptionMenu with red background

like image 122
patthoyts Avatar answered Dec 05 '25 05:12

patthoyts


To change the background of the drop down menu:

my_optionmenu["menu"].configure(bg="black")

If you run:

print(my_optionmenu["menu"].keys())

you get all of the options you can change for the OptionMenu widget

like image 29
RVACode Avatar answered Dec 05 '25 03:12

RVACode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!