Tkinter callback problem

Ian Terrell kife00 at yahoo.com
Thu Mar 13 18:18:08 CET 2003


I'm trying to run the following code I found in some tutorial:

------------------------------------------
from Tkinter import *

def button1(event):
    print "Clicked at",event.x,event.y

root = Tk()

frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", button1)
frame.pack()

root.mainloop()
------------------------------------------

It starts up just fine.  However, when I click on the window, I get
the following runtime error:

------------------------------------------
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 1300, in
__call__
    args = apply(self.subst, args)
  File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 1036, in
_substitute
    e.height = getint(h)
ValueError: invalid literal for int(): ??
------------------------------------------

Now, to fix this, I started by commenting out the e.height = getint(h)
line, and got more errors of the same variety for other variables.  If
I comment out the following lines from Tkinter.py's _substitute
function, it works perfectly:

#        e.height = getint(h)
#        e.keycode = getint(k)
#        e.width = getint(w)
#        e.keysym_num = getint(N)

Is this something to do with the fact that a frame was clicked in? 
Perhaps frames don't have heights, keycodes, widths, or keysys_nums?

Is there a more elegant solution to this so that it works?

Thanks.
Ian




More information about the Python-list mailing list