Tkinter focus problem

Richard Kuhns rjkuhns at geetel.net
Wed Dec 11 11:02:53 EST 2002


Well, I'm back again.  This time, though, I actually have working code;
it's just that I don't understand why some other code doesn't work, and
I'd really like to.

Briefly, I want <Return>/<KP_Enter> to function like <Tab> (ie, advance to
the next widget that will accept focus).  I realize that there are other
ways to approach this, but I thought this should be fairly straightforward
to start with. This is for an application where all data will normally be
entered via the keypad.

In my data entry widget I have the following:

    self.bind_all('<Return>', self._nextWin)

    def _nextWin(self, event):
        """Make other keys act like <Tab>.
        """
        nextwin = self.tk.call('tk_focusNext', event.widget)
        print "+++focus_next() says", self.tk_focusNext()
        print "+++call to tk says  ", nextwin
        self.tk.call('tkTabToWindow', nextwin)

What I don't understand is why
"self.tk.call('tk_focusNext', event.widget)"
and
"self.tk_focusNext()"

always return different values.  _nextWin() works like I want the way it's
written above (minus the prints), but I'd like to know why
self.tk_focusNext() doesn't.  I think I'm finally beginning to get my
brain wrapped around Tkinter, but I'm not quite there yet.

Thanks for any comments.
-- 
Richard Kuhns			rjkkuhns at geetel.net




More information about the Python-list mailing list