python - 基于 OptionMenu 选择改变 Tkinter 按钮的命令功能
问题描述
我在 python 中使用 Tkinter,并且有一个带有各种选项和一个按钮的下拉菜单。我希望这个按钮的命令功能根据下拉菜单的选择而改变。但是,我对选择变量的初始设置似乎没有改变。我该如何解决这个问题?目前,似乎我的初始设置clicked
导致按钮以一种方式配置,并且不会根据用户选择而改变。
def get_chosen_opp(clicked):
return clicked.get()
clicked=StringVar() #this will be the chosen team
drop=OptionMenu(self,clicked,"Catholic","Coast Guard","Maine Maritime","Merchant Marine","Norwich","Springfield","WPI","Non-Conference Opponent")
clicked.set("Non-Conference Opponent")
drop.place(relx=.5,rely=.35,anchor='n',relheight=.1,relwidth=.4)
lower_frame=tk.Frame(self,bd=5,bg='#252122')
lower_frame.place(relx=.5,rely=.6,relwidth=0.35,relheight=.1,anchor='n')
continue_button=tk.Button(lower_frame,text='See Chart',font=30,bg='#7F120E')
#set custom stats if non-conference oponent
selection=get_chosen_opp(clicked)
if selection=="Non-Conference Opponent":
continue_button.config(command=lambda:controller.show_label(set_nc_stats))
else:
continue_button.config(command=lambda:controller.show_label(show_chart))
continue_button.place(relheight=1,relwidth=1)
解决方案
推荐阅读
- environment-variables - 如何访问 Nuxt 插件中的 .env 变量?
- r - 在 R 中编辑 .clog 文件
- python - 动态定义函数在类对象中不起作用?
- r - 许多二进制列:需要使用第二个数据帧中的分组信息减少到更少的二进制列
- jquery - WordPress/Elementor 实现类似 React 的 Framer's Motion 的页面过渡效果
- azure-active-directory - 使用与 AzureAD 共享机密的 OBO 请求获取 SAML 令牌时出错
- android - 当导航到可组合时,我们如何隐藏 BottomAppBar(包含导航)?
- material-ui - XGrid 或 Data Grid:如何在工具栏中限制过滤器运算符?
- python - Django Admin 模型列表渲染
- docker-compose - 如何覆盖 docker-compose 文件中的 X 属性?