Tkinter focus problem
Eric Brunel
eric.brunel at pragmadev.com
Wed Dec 11 12:51:33 EST 2002
Richard Kuhns wrote:
> 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.
Look carefully: the call self.tk.call('tk_focusNext', event.widget) passes
a widget to the tk command tk_focusNext. The equivalent in Tkinter would
be to call the method tk_focusNext on event.widget, not on self.
self.tk_focusNext() returns the widget following self, which is obviously
not the same than the one following event.widget...
HTH
--
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
More information about the Python-list
mailing list