简体   繁体   English

Tkinter OptionMenu 参数

[英]Tkinter OptionMenu arguments

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.我不能用 Tkinter 中的OptionMenu类来做到这一点。 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'.这导致参数“master”有多个值。 How can I explicitly define the master, variable, and list of options to use?如何显式定义要使用的主选项、变量和选项列表?

Unfortunately, the OptionMenu widget is somewhat poorly implemented.不幸的是, OptionMenu小部件的实现有些糟糕。 Regardless of your preferences, the optionmenu isn't designed to accept keyword arguments for the first three parameters master , variable , and value .无论您的偏好如何,optionmenu 都不会接受前三个参数mastervariablevalue关键字参数。 They must be presented in that order as positional arguments.它们必须按该顺序作为位置参数出现。

self.menu_m = tk.OptionMenu(self.frame_1, self.var, *choices)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM