如何根据下拉菜单中的选择动态填充 tkinter 中的选项小部件?
我的问题如下:我有几个文件,并且我已经制作了一个包含名称的下拉菜单,接下来我需要的是一个选项菜单,只要选择文件名即可更改该菜单以显示特定文件中的一些数据,如下所示选项。需要明确的是,我的问题只是关于如何在选择下拉列表中的选项时更改选项菜单。感谢您的帮助。
my problem is the following: I have several files and I have made a drop down menu with the names,the next thing I need is an option menu which can be changed whenever a file name is selected to show some data from the specific file as option.To be clear,my question is only about how to make the option menu change when a choice from the drop down is selected.Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OptionMenu 小部件只不过是一个方便的类,它创建与菜单关联的菜单按钮。您可以通过
"menu"
属性访问此菜单。唯一的技巧是知道菜单项应该做什么,无非是设置关联变量的值。这是一个例子:
The OptionMenu widget is nothing more than a convenience class that creates a menubutton that is associated with a menu. You can get at this menu via the
"menu"
attribute. The only trick is to knowing what the menu items should do, which is nothing more than setting the value of the associated variable.Here's an example:
由于 OptionMenu 提供了一个命令选项,我建议保留对已经给出的命令(如果有)的引用,并以这种方式将其传递给新选项:
参加,基于先前答案的变量
希望它有任何用处
顺便说一句,布莱恩·奥克利给出的答案非常有用,
As the OptionMenu gives a command option, i would suggest to keep reference to the command already given (if any) and pass it to the new options this way:
attendion, variables based on the previous answer
Hope its of any use
Btw, really usefull the answer given by Bryan Oakley,