grab
Keeps the pointer events of the application in one widget and its descendants.
grab ?-global? WINDOW
grab SUBCOMMAND ?ARG ...?
Description
While a widget has the grab, a pointer event over a widget outside its tree goes to the grab widget. A dialog uses a grab so that a click on the main window does not reach the widgets of the main window. The application has at most one grab, and a new grab replaces the old one. The grab ends when its widget is destroyed.
grab WINDOW is the same as grab set WINDOW. ztk has local grabs only. -global is accepted and gives a local grab, because a program cannot take the pointer of other programs on Wayland. grab status gives global for such a grab. event generate is not affected by a grab.
Subcommands
| Subcommand | Description |
|---|---|
grab set | Gives the grab to a widget. |
grab release | Ends the grab of a widget. |
grab current | Gives the widget with the grab. |
grab status | Gives the grab status of a widget: none, local, or global. |
Examples
# The click is over `.main`, and it goes to the grab widget `.dlg`.
% frame .dlg -width 20 -height 20
> frame .main -width 20 -height 20
> pack .dlg .main
> update
> bind .dlg <1> {lappend ::got dlg}
> bind .main <1> {lappend ::got main}
> grab .dlg
> set ::got {}
> ztk::inject . press 1 5 25
> ztk::inject . release 1 5 25
> update
> set got
dlg
% grab release .dlg
> set ::got {}
> ztk::inject . press 1 5 25
> ztk::inject . release 1 5 25
> update
> set got
main
Errors
% grab
wrong # args: should be "grab ?-global? window" or "grab option ?arg ...?"
-errorcode NONE
% grab bogus
bad option "bogus": must be current, release, set, or status
-errorcode NONE
% grab .nope
bad window path name ".nope"
-errorcode NONE
Differences from Tcl
- The errors of
grabhave the-errorcodeNONE, except the errors of the count of arguments of a subcommand. Tk 8.6.16 gives a code such asTK LOOKUP WINDOW. - A global grab is a local grab in ztk: pointer events of other programs stay with those programs.
- A widget that is not on the screen can get the grab in ztk. Tk 8.6.16 gives the error
grab failed: window not viewable. grab currentwith the name of a widget that does not exist gives an empty list while no widget has the grab. Tk 8.6.16 gives the errorbad window path name.- The subcommands and
-globalneed their full names. Tk 8.6.16 accepts a unique short form, such as-gfor-global.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1