Sha*_*aun 2 python tkinter optionmenu
我喜欢明确指定参数。例如:
def func(a, b):
return a+b
Run Code Online (Sandbox Code Playgroud)
每当我调用它时,我都会写:
func(a=6, b=7)
Run Code Online (Sandbox Code Playgroud)
代替:
func(6, 7)
Run Code Online (Sandbox Code Playgroud)
我不能用OptionMenuTkinter 中的类来做到这一点。以下示例位于自定义类中
self.var = tk.StringVav()
choices = ['op1', 'op2']
self.menu_m = tk.OptionMenu(master=self.frame_1, variable=self.var, *choices)
Run Code Online (Sandbox Code Playgroud)
这导致参数“master”有多个值。如何显式定义要使用的主选项、变量和选项列表?
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)
Run Code Online (Sandbox Code Playgroud)