Tkinter - tk_focusNext broken for years?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Helmut Jarausch

    Tkinter - tk_focusNext broken for years?

    Hi,

    I'd like to bind the '<Return>' event to a function
    which does some calculations (like a database lookup)
    and then invoke tk_focusNext.
    I get an exception as many others have reported earlier, see

    There has even a patch been suggested. Why hasn't it been fixed -
    I haven't seen a fix.
    The problem can be reproduced by the following tiny script
    I'm using Python 2.5.1 .

    Should I fixed the Tkinter source myself or is there a workaround?

    Many thanks for your help,
    Helmut.
    -------------------------------------------
    import Tkinter as Tk

    def Proc_Enter(Even t) :
    print "Enter - normally lookup a database"
    Event.widget.tk _focusNext()

    root= Tk.Tk()
    Tk.Label(root,t ext='Name').gri d(column=0,row= 0,sticky=Tk.W)
    Nm_input= Tk.StringVar()
    Nm_entry= Tk.Entry(root,t extvariable=Nm_ input)
    Nm_entry.bind(' <Return>',Proc_ Enter)
    Nm_entry.grid(c olumn=1,row=0,s ticky=Tk.W)

    Tk.Label(root,t ext='City').gri d(column=0,row= 1,sticky=Tk.W)
    City_input= Tk.StringVar()
    City_entry= Tk.Entry(root,t extvariable=Cit y_input)
    City_entry.bind ('<Return>',Pro c_Enter)
    City_entry.grid (column=1,row=1 ,sticky=Tk.W)

    Tk.mainloop()
    -------------------------------------------
    >>>>>>>>>>>>
    Exception in Tkinter callback
    Traceback (most recent call last):
    File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__
    return self.func(*args )
    File "FocusBug.p y", line 6, in Proc_Enter
    Event.widget.tk _focusNext()
    File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 479, in tk_focusNext
    return self._nametowid get(name)
    File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1064, in nametowidget
    if name[0] == '.':
    TypeError: '_tkinter.Tcl_O bj' object is unsubscriptable
    -------------------------------------------

    --
    Helmut Jarausch

    Lehrstuhl fuer Numerische Mathematik
    RWTH - Aachen University
    D 52056 Aachen, Germany
Working...