python - Tkinter 将选项链接到功能并使用按钮调用它
问题描述
我有一个选项列表:
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])
有什么方法可以跟踪用户的实时选择吗?
谢谢。
解决方案
推荐阅读
- java - 如何通过端口获取tomcat进程ID并结束该进程
- php - 无法显示 ajax 结果 WordPress
- c++ - Bazel 使用 soname 创建 C++ 共享库
- javascript - AngularJS ng-repeat 在地图(对象)上不实时更新 DOM
- azure - CosmosDB 表 API - 此 API 不支持 CORS 规则
- jquery - 查找包含相同文本的每组 div 的第一个实例
- gradle - 使用 Gradle 在 Dagger 2 中插入组件模块
- javascript - 请求函数中的 NodeJS 全局变量
- spring - Spring Session 不使用自定义 RedisTemplate bean
- php - 如何让我的会话数据正确存储?