Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter Optionmenu callback not working

Tags:

python

tkinter

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 i.e. 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.

What am I doing wrong here?

like image 959
Jakob Avatar asked Feb 13 '26 20:02

Jakob


1 Answers

The optionmenu is designed to set a value, not perform an action. 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.

like image 199
Bryan Oakley Avatar answered Feb 17 '26 13:02

Bryan Oakley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!