I like to explicitly specify arguments. For example:
def func(a, b):
return a+b
Anytime I call it I write:
func(a=6, b=7)
Instead of:
func(6, 7)
I can't do this with the OptionMenu
class in Tkinter. The following example is within a custom class
self.var = tk.StringVav()
choices = ['op1', 'op2']
self.menu_m = tk.OptionMenu(master=self.frame_1, variable=self.var, *choices)
This results in multiple values for the argument 'master'. How can I explicitly define the master, variable, and list of options to use?
Unfortunately, the OptionMenu
widget is somewhat poorly implemented. Regardless of your preferences, the optionmenu isn't designed to accept keyword arguments for the first three parameters master
, variable
, and value
. They must be presented in that order as positional arguments.
self.menu_m = tk.OptionMenu(self.frame_1, self.var, *choices)