我有一个选项列表:
OPTIONS = [
"Algorithm 1",
"Algorithm 2"
]
我想在下面将此功能链接到选项算法1:
def combine_funcs(*funcs):
def combined_func(*args, **kwargs):
for f in funcs:
f(*args, **kwargs)
return combined_func
这里是我尝试做的事情:
SelectedOptions = StringVar(top)
SelectedOptions.set(OPTIONS[0])
typeOption = OptionMenu(top, SelectedOptions, *OPTIONS)
这是我的开始按钮:
self.Button1 = tk.Button(top, command = functionschoose())
self.Button1.place(relx=0.839, rely=0.917, height=35, width=62)
这是我要选择要运行的算法的功能
def functionschoose():
if SelectedOptions.get() == "Algorithm 1":
return combine_funcs(popup_bonus, callback)
else:
print "second func" # this is still empty because the algorithm has not been implemented yet.
目前,使用.get()获取的算法始终似乎是算法1
我认为这是由于SelectedOptions.set(OPTIONS [0])
有什么方法可以跟踪用户的实时选择?
谢谢。