[Tkinter-discuss] tk_focusNext and tkfocusPrev

Russell E. Owen rowen at cesmail.net
Thu Feb 14 21:38:17 CET 2008


In article <47B3F0A1.5080206 at gatwick.westerngeco.slb.com>,
 Martin Franklin <mfranklin1 at gatwick.westerngeco.slb.com> wrote:

> Hunter0000 wrote:
> > Hello,
> > 
> > Can anyone give an example of how to use these two methods? I've tried using
> > them is various ways (the end goal being to replicate forward and reverse
> > tabbing) but it always comes out saying either it doesn't exist or the
> > object it returns in unsubscriptable. Any of the documentation I can find
> > about most of the focus-related methods seems spotty at best, and in this
> > case nonexistent, so an actual working example would be great to work from.
> > 
> > Mike
> 
> No idea myself, but this seems a decent explanation:-
> 
> http://docs.huihoo.com/tkinter/tkmanual/focusNext.html
> 
> 
> Found with the power of Google :) - its a copy of the Tk man page in 
> fact....
> 
> 
> Now as to the real problem... tk_focusNext deal in windows (whole 
> windows not single widgets) so... I think you want to use focus_get and 
> focus_set like so:-

Actually a "window" in tk is a widget. A "whole window" is called a 
"toplevel" in tk. I find it disconcerting, but at least once I got the 
hang of that I found the tk documentation made a lot more sense.

Also focusNext always stays within the current toplevel (according to 
the manual). But it looks like it only gives you the name of the next 
widget (window). So I think the solution to the original poster's 
question is:

currWdg.tk_focusNext().focus_set()

-- Russell



More information about the Tkinter-discuss mailing list