[Tkinter] event problem

Discussion in 'Python' started by Ivan Letal, Sep 24, 2003.

  1. Ivan Letal

    Ivan Letal Guest

    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(): ??
     
    Ivan Letal, Sep 24, 2003
    #1
    1. Advertising

  2. Ivan Letal

    Peter Otten Guest

    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
     
    Peter Otten, Sep 24, 2003
    #2
    1. Advertising

  3. In article <bks0va$9mv$>,
    Ivan Letal <> wrote:

    >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
     
    Russell E. Owen, Sep 25, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wang xiaoyu
    Replies:
    0
    Views:
    864
    wang xiaoyu
    Jun 25, 2003
  2. Jeff Epler
    Replies:
    0
    Views:
    510
    Jeff Epler
    Aug 20, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    459
    Jeff Epler
    Aug 23, 2004
  4. Pierre Dagenais
    Replies:
    0
    Views:
    319
    Pierre Dagenais
    Aug 3, 2008
  5. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    1,694
    rantingrick
    Jun 23, 2010
Loading...

Share This Page