beetlebug▾
/

tkwait

Runs the event loop until a variable changes, a widget shows, or a widget is destroyed.

tkwait variable NAME
tkwait visibility WINDOW
tkwait window WINDOW

Description

tkwait runs events, timers of after, and bindings until its condition is true, and then returns. The script after the call runs only then, so a dialog procedure can wait for the answer of the user and give it as its result. Each event of the application runs during the wait, also events of other windows.

When no event can come, such as in ztk --headless with no timer and no input left, the wait gives the error can't wait for KIND "NAME": would wait forever. The subcommands accept a short form of two or more letters, such as va for variable.

Returns

An empty string.

Examples

% after 10 {set ::answer yes}
> tkwait variable ::answer
> set answer
yes

% toplevel .dlg
> after 10 {destroy .dlg}
> tkwait window .dlg
> winfo exists .dlg
0

% frame .f
> pack .f
> tkwait visibility .f
> winfo ismapped .f
1

% after 10 {set ::short 1}
> tkwait va ::short

Errors

% tkwait
wrong # args: should be "tkwait variable|visibility|window name"
-errorcode TCL WRONGARGS

% tkwait window .nope
bad window path name ".nope"
-errorcode NONE

% frame .g
> after 10 {destroy .g}
> tkwait visibility .g
window ".g" was deleted before its visibility changed
-errorcode NONE

# No timer or event can set the variable.
% tkwait variable ::never
can't wait for variable "::never": would wait forever
-errorcode NONE

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also