[Tkinter] event problem

I

Ivan Letal

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(): ??
 
P

Peter Otten

Ivan said:
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
 
R

Russell E. Owen

Ivan Letal said:
I have just tried this code....
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(): ??

I think you are running mutually incompatible versions of Python and Tk.
Python 2.2.2 and earlier need Tk 8.4.1 or earlier. Python 2.3 is
compatible with later versions of Tk.

-- Russell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top