Search code examples
python-3.xtkinterttk

In Python3/tkinter Is there a way to change the background color of the arrows in a ttk.Menubutton?


I have a tkinter interface that uses ttk widgets and would like to have a ttk.MenuButton with gray arrows, in macOSX. Is that possible?

I am creating my Menubutton using this code (self.topframe is a ttk.Frame object):

self.label_menu_btn = ttk.Label(self.topframe, font=self.btnFont, foreground=self.btnTxtColor, text="Copiar…")
self.menu_btn =  ttk.Menubutton (self.topframe, text="•••")
self.menu_btn.menu  =  Menu (self.menu_btn, tearoff=0)
self.menu_btn["menu"] =  self.menu_btn.menu

self.menu_btn.menu.add_command(label="Número de objeto", command=self.copiar_obj_num, accelerator="Command+c")

This is what my button looks like:

enter image description here

And this is what I have found in another app, similar to what I want to accomplish:

enter image description here


Solution

  • To do this with ttk you need to first edit the style, then apply it to the widget. It will look something like this.

    s = ttk.Style()
    s.configure('MyStyle.TMenubutton', background='pink')
    
    var = tk.StringVar()
    widget = ttk.OptionMenu(root, var, 'ANY', 'ANY', '0', '1', style="MyStyle.TMenubutton")
    

    Where "MyStyle" is the name of the style you are creating and "TMenubutton" is the name of the style you are forking from.