tk_focusNext(3tk)
β¨ NAME β¨
tk_focusNext, tk_focusPrev, tk_focusFollowsMouse β the lil utility squad that handles input focus management π
(this is tk_focusNext(3tk), from the Tk Built-In Commands fam, hiii π«Ά)
πΈ SYNOPSIS πΈ
tk_focusNext window
tk_focusPrev window
tk_focusFollowsMouse
π¦ DESCRIPTION π¦
Okay so bestie, let me put you on. tk_focusNext is a utility procedure for keyboard traversal β it hands you back the βnextβ window after window in focus order. Iconic behaviour, honestly.
So how is the focus order decided? Two things, and only two: the stacking order of windows, and the structure of the window hierarchy. That's it, that's the whole vibe.
Among siblings, focus order == stacking order, and the lowest window comes first. The way that works is: if a window has children, the window itself gets visited first π, then its children (recursively, yes queen, all the way down π), and then its next sibling. Also β top-level windows other than window get skipped, so tk_focusNext will never return a window in a different top-level from window. No cross-top-level shenanigans, periodt.
Once it's computed the next window, tk_focusNext peeks at that window's -takefocus option to see if it should be skipped. If it should, tk_focusNext just keeps going β next window in focus order, and the next, and the next β until it either finds a window that will actually accept the focus, or it loops all the way back to window. π―
tk_focusPrev? Literally the same energy, except it returns the window just before window in the focus order. Mirror version, no cap. πͺ
π tk_focusFollowsMouse π
This one is a whole personality change for your app β it switches the focus model to an implicit one where the window under the mouse gets the focus π±οΈβ¨.
After you call this procedure, whenever the mouse enters a window, Tk will automatically give it the input focus. You can still use the focus command to move focus to a window other than the one under the mouse β but the absolute second the mouse moves into a new window, the focus jumps to that one instead. It's giving very "wherever the mouse goes, I go" ππ
β οΈ Heads up bestie: at present there is no built-in support for returning the application to an explicit focus model. If you wanna go back, you have to write a script yourself that deletes the bindings created by tk_focusFollowsMouse. So like... choose wisely before you commit π
π KEYWORDS π
- focus
- keyboard traversal
- top-level
And that's the whole page, bestie!! This lil masterpiece is from the Tk Built-In Commands, version 4.0, and the page itself is tk_focusNext(3tk) β go forth and traverse those windows like the main character you are πβπ
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms