Tkinter question (reposted)

Russell E. Owen owen at nospam.invalid
Thu May 30 14:11:25 EDT 2002


In article <ufcanbc9qafp83 at corp.supernews.com>,
 "Michael Bauers" <me at michaelbauers.com> wrote:

>The online docs had a code snippet that was not working as shown.  I had to
>remove the 'event' parameter from the callback 'cb'.  Did I mess up, or is
>this a matter of version differences between the doc, and Python 2.2?
>
>My modified def line looked like:
>   def cb(self)
>
>This is what was in the docs:
>
>def __init__(self, master):
>        self.var = IntVar()
>        c = Checkbutton(master, text="Enable Tab",
>                        variable=self.var, command=self.cb)
>        c.pack()
>
>    def cb(self, event):
>        print "variable is", self.var.get()

The example you copied was apparently in error. This is a common 
problem. Tkinter sends the event to callbacks that are fired by binding 
events to widgets. it does NOT send the event parameter for callbacks 
that are fired directly by widgets (using the "command" parameter to 
specify the callback). This inconsistency is a pity; not only is it 
confusing, but the event info would often be useful.

-- Russell



More information about the Python-list mailing list