[Tkinter] event problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Letal

    [Tkinter] event problem

    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("<Bu tton-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.subs t, 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(): ??

  • Peter Otten

    #2
    Re: [Tkinter] event problem

    Ivan Letal wrote:
    [color=blue]
    > 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("<Bu tton-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.subs t, 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(): ??[/color]


    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(sel f, *args):
    """Internal function."""
    if len(args) != len(self._subst _format): return args
    getboolean = self.tk.getbool ean

    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

    Comment

    • Peter Otten

      #3
      Re: [Tkinter] event problem

      Ivan Letal wrote:
      [color=blue]
      > 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("<Bu tton-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.subs t, 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(): ??[/color]


      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(sel f, *args):
      """Internal function."""
      if len(args) != len(self._subst _format): return args
      getboolean = self.tk.getbool ean

      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

      Comment

      • Russell E. Owen

        #4
        Re: [Tkinter] event problem

        In article <bks0va$9mv$1@n s.felk.cvut.cz> ,
        Ivan Letal <admin4055@cent rum.cz> wrote:
        [color=blue]
        >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.subs t, 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(): ??[/color]

        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

        Comment

        Working...