[Tkinter] event problem

Peter Otten __peter__ at web.de
Wed Sep 24 08:41:30 EDT 2003


Ivan Letal wrote:

> I have just tried this code..
> 
> Tkinter import *
> 
> root = Tk()
> 
> def callback(event):
>      print "clicked at", event.x, event.y
> 
> frame = Frame(root, width=100, height=100)
> frame.bind("<Button-1>", callback)
> frame.pack()
> root.mainloop()
> 
> .. on my SuSE Linux 8.2, Python 2.2.2, python-tk 2.2.2.
> 
> This opens a new window, but there is a problem when I click on it. I
> tried similar code where clicking on a button does the same. Can anyone
> help?
> 
> Here is the error:
> 
> Exception in Tkinter callback
> Traceback (most recent call last):
>    File
> "/var/tmp/python-2.2.2-build//usr/lib/python2.2/lib-tk/Tkinter.py", line
> 1299, in __call__
>      args = apply(self.subst, args)
>    File
> "/var/tmp/python-2.2.2-build//usr/lib/python2.2/lib-tk/Tkinter.py", line
> 1035, in _substitute
>      e.height = getint(h)
> ValueError: invalid literal for int(): ??


No problems with your code here (Suse 8.1, Python 2.3).

The relevant portion of 2.3's Tkinter.py has an interesting comment together
with what seems to be a Tk workaround:

[...]
    def _substitute(self, *args):
        """Internal function."""
        if len(args) != len(self._subst_format): return args
        getboolean = self.tk.getboolean

        getint = int
        def getint_event(s):
            """Tk changed behavior in 8.4.2, returning "??" rather more
often."""
            try:
                return int(s)
            except ValueError:
                return s
[...]

So, if that's an option, upgrading to 2.3 should solve your problem.

Peter




More information about the Python-list mailing list