More concise way to configure tkinter option menu? More concise way to configure tkinter option menu? tkinter tkinter

More concise way to configure tkinter option menu?


If you are going to create several menus with the same configuration, I would subclass OptionMenu instead of defining a function:

from Tkinter import*class MyOptionMenu(OptionMenu):    def __init__(self, master, status, *options):        self.var = StringVar(master)        self.var.set(status)        OptionMenu.__init__(self, master, self.var, *options)        self.config(font=('calibri',(10)),bg='white',width=12)        self['menu'].config(font=('calibri',(10)),bg='white')root = Tk()mymenu1 = MyOptionMenu(root, 'Select status', 'a','b','c')mymenu2 = MyOptionMenu(root, 'Select another status', 'd','e','f')mymenu1.pack()mymenu2.pack()root.mainloop()

In my example, I have supposed the only thing that is going to change is the options, but if each instance has its own background color or font, then you only have to add it as an argument to the __init__ method.