Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are the limitations of callback functions associated with Tkinter traces?
    primarykey
    data
    text
    <p>I am trying to figure out exactly how to implement a callback function which does something more meaningful than just print output. I am fairly inexperienced, so I am not sure how callback functions should or can be implemented in Python (or in any other language, for that matter).</p> <p>Consider the following Python code:</p> <pre><code>from Tkinter import * def callbackfunc(*args): print "Hello World!" class App: def __init__(self, master): frame = Frame(master) frame.pack() optionvalue = IntVar(master) optionvalue.set(2) optionvalue.trace("w", callbackfunc) self.optionmenu = OptionMenu(master, optionvalue, 1, 2, 3, 4) self.optionmenu.pack() </code></pre> <p>I am trying to implement an OptionMenu (a Tkinter widget) such that when its selected value is changed, my callback function does something meaningful---more specifically, it will change a global variable value, defined somewhere else in the program. As it is implemented above, it simply prints output (albeit successfully).</p> <p>I cannot figure out how to pass parameters to my callback function. I do not want this particular callback function to return anything; however, I am curious as to how I would make my callback function return something, and how I would implement the rest of my program so that it could utilize those returned results, whatever those might be. Am I trying to implement a Python callback function in a way in which it was not intended to be implemented? If not, how do I make this one work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload