busy(n)
β¨ NAME β¨
okay bestie, meet busy(n) from Tk Built-In Commands. Itβs called busy and its whole thing is: make Tk widgets busy, temporarily blocking user interactions. Iconic behavior, honestly. π
π SYNOPSIS π
tk busy window ?options?
tk busy busywindow window
tk busy hold window ?options?
tk busy configure window ?option value?...
tk busy forget window ?window ?...
tk busy current ?pattern?
tk busy status window
π DESCRIPTION π
The tk busy command is your simple little means to block mouse pointer events from Tk widgets while overriding the widgetβs cursor with a configurable busy cursor. Slay for feedback. Important vibe check: this command does not prevent keyboard events from being sent to the widgets made busy. No cap.
π¦ INTRODUCTION π¦
There are so many times in apps where you want to temporarily restrict what actions the user can take. For example, an app could have a βRunβ button that, when pressed, causes some processing to occur. But while the app is busy processing, you probably donβt want the user to be able to click the βRunβ button again. You might also want to restrict the user from other tasks, like clicking a βPrintβ button.
The tk busy command lets you make Tk widgets busy. That means user interactions such as button clicks, moving the mouse, typing at the keyboard, etc. are ignored by the widget. You can set a special cursor (like a watch) that overrides the widgetβs normal cursor, giving feedback that the application/widget is temporarily busy. Itβs giving βplease hold, main character is processingβ energy. β
When a widget is made busy, the widget and all of its descendants will ignore pointer events. Itβs easy to make an entire panel of widgets busy: just make the toplevel widget (such as .) busy. That is easier and far much more efficient than recursively traversing the widget hierarchy, disabling each widget, and re-configuring its cursor. Lowkey a glow-up for your event handling.
Often, the tk busy command can be used instead of Tkβs grab command. Unlike grab, which restricts all user interactions to one widget, with tk busy you can have more than one widget active (for example, a βCancelβ dialog and a βHelpβ button). Bestie said multitasking. π«Ά
πΈ EXAMPLE πΈ
You can make several widgets busy by simply making its ancestor widget busy using the hold operation.
frame .top
button .top.button; canvas .top.canvas
pack .top.button .top.canvas
pack .top
# . . .
tk busy hold .top
update
All the widgets within .top (including .top) are now busy. Using update insures that the tk busy command will take effect before any other user events can occur.
When the application is no longer busy processing, you can allow user interactions again and free any resources it allocated by using the forget operation.
tk busy forget .top
The busy window has a configurable cursor. You can change the busy cursor using the configure operation.
tk busy configure .top -cursor "watch"
Destroying the widget will also clean up any resources allocated by the tk busy command. We love automatic cleanup. π§
π OPERATIONS π
The following operations are available for the tk busy command:
tk busy window ?option value?...β Shortcut for thetk busy holdcommand.tk busy busywindow windowβ Returns the pathname of the busy window (i.e. the transparent window shielding the window appearing busy) created by thetk busy holdcommand for window, or the empty string if window is not busy.tk busy cget window optionβ Queries thetk busycommand configuration options for window. window must be the path name of a widget previously made busy by theholdoperation. The command returns the present value of the specified option. option may have any of the values accepted by theholdoperation.tk busy configure window ?option value?...β Queries or modifies thetk busycommand configuration options for window. window must be the path name of a widget previously made busy by theholdoperation. If no options are specified, a list describing all of the available options for window is returned (seeTk_ConfigureInfofor information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option; this list will be identical to the corresponding sublist of the value returned if no option is specified. If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns the empty string. option may have any of the values accepted by theholdoperation.
Please note that the option database is referenced through window. For example, if the widget .frame is to be made busy, the busy cursor can be specified for it by either option command:
option add *frame.busyCursor gumby
option add *Frame.BusyCursor gumby
tk busy current ?pattern?β Returns the pathnames of all widgets that are currently busy. If a pattern is given, only the path names of busy widgets matching pattern are returned.tk busy forget window ?window?...β Releases resources allocated by thetk busycommand for window, including the transparent window. User events will again be received by window. Resources are also released when window is destroyed. window must be the name of a widget specified in theholdoperation, otherwise an error is reported.tk busy hold window ?option value?...β Makes the specified window (and its descendants in the Tk window hierarchy) appear busy. window must be a valid path name of a Tk widget. A transparent window is put in front of the specified window. This transparent window is mapped the next time idle tasks are processed, and the specified window and its descendants will be blocked from user interactions. Normallyupdateshould be called immediately afterward to insure that theholdoperation is in effect before the application starts its processing. The command returns the pathname of the busy window that was created (i.e. the transparent window shielding the window appearing busy). The following configuration options are valid:-cursor cursorNameβ Specifies the cursor to be displayed when the widget is made busy.cursorNamecan be in any form accepted byTk_GetCursor. The default cursor iswaiton Windows andwatchon other platforms.
tk busy status windowβ Returns the status of a widget window. If window presently can not receive user interactions,1is returned, otherwise0.
π EVENT HANDLING π
π BINDINGS π
The event blocking feature is implemented by creating and mapping a transparent window that completely covers the widget. When the busy window is mapped, it invisibly shields the widget and its hierarchy from all events that may be sent. Like Tk widgets, busy windows have widget names in the Tk window hierarchy. This means that you can use the bind command to handle events in the busy window:
tk busy hold .frame.canvas
bind [tk busy busywindow .frame.canvas] <Enter> { ... }
or
set busyWin [tk busy hold .frame.canvas]
bind $busyWin <Enter> { ... }
π ENTER/LEAVE EVENTS π
Mapping and unmapping busy windows generates Enter/Leave events for all widgets they cover. Please note this if you are tracking Enter/Leave events in widgets. π
β¨οΈ KEYBOARD EVENTS β¨οΈ
When a widget is made busy, the busy window prevents the widget from gaining keyboard focus when a user clicks on it. But if the widget already had focus, it still may receive keyboard events. The widget can also still receive focus through keyboard traversal. To prevent this, you must move focus to another window and make sure the focus can not go back to the widgets made busy (e.g. by restricting focus to a cancel button).
pack [frame .frame]
pack [text .frame.text]
tk busy hold .frame
pack [button .cancel -text "Cancel" -command exit]
focus .cancel
bind .cancel <Tab> {break}
bind .cancel <Shift-Tab> {break}
update
The above example moves the focus from .frame immediately after invoking the hold so that no keyboard events will be sent to .frame or any of its descendants. It also makes sure itβs not possible to leave button .cancel using the keyboard. Periodt. β¨οΈβ¨
π§ PORTABILITY π§
Note that the tk busy command does not currently have any effect on macOS when Tk is built using Aqua support. Noted, bestie.
π₯ SEE ALSO π₯
β KEYWORDS β
busy, keyboard events, pointer events, window
π okay thatβs the whole busy(n) page, bestie! Source/version: Tk; manual: busy(n); and the footer doesnβt show a date, so no fake date era β periodt. π
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- nixpkgs unstable: tk 9.1.0
- Copyright (c) 1993-1998 Lucent Technologies, Inc
- Copyright (c) 2008 Jos Decoster
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms