简体   繁体   English

Tkinter Optionmenu回调无法正常工作

[英]Tkinter Optionmenu callback not working

For some reason I can't get this optionmenu so call the callback function. 出于某种原因,我无法获得此选项菜单,因此请调用回调函数。 Is there some special treatment those widgets require? 这些小部件需要一些特殊处理吗? (The function itself works and I can call it from ie a button.) (函数本身可以工作,我可以从一个按钮调用它。)

self.shapemenu=Tkinter.OptionMenu(self.frame,self.shape,"rectangle", "circular", command=self.setshape)

self.shape is a Tkinter.StringVar and obviously setshape is the callback function. self.shape是一个Tkinter.StringVar,显然setshape是回调函数。

What am I doing wrong here? 我在这做错了什么?

The optionmenu is designed to set a value, not perform an action. optionmenu旨在设置值,而不是执行操作。 You can't assign a command to it, and if you do, you will break its default behavior of setting the value -- it uses the command option internally to manage its values . 您无法为其分配命令,如果这样做,您将破坏其设置值的默认行为 - 它在内部使用命令选项来管理其值。

If you want something to happen when the value changes, add a trace on the StringVar. 如果您希望在值更改时发生某些事情,请在StringVar上添加跟踪。

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

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