[manual index][section index]


grab - Confine pointer and keyboard events to a window sub-tree


grab what ?arg arg ...?


This command implements simple pointer grabbing for Tk. When a grab is set for a particular window, Tk restricts all pointer events to the grab window and its descendants in Tk's window hierarchy. Whenever the pointer is within the grab window's subtree, the pointer will behave exactly the same as if there had been no grab at all and all events will be reported in the normal fashion. When the pointer is outside window's tree, button presses and releases and mouse motion events are reported to window, and window entry and window exit events are ignored. The grab subtree ``owns'' the pointer: windows outside the grab subtree will be visible on the screen but they will be insensitive until the grab is released. The tree of windows underneath the grab window can include top-level windows, in which case all of those top-level windows and their descendants will continue to receive mouse events during the grab.

A grab locks out all applications on the screen, so that only the given subtree of the grabbing application will be sensitive to pointer events (mouse button presses, mouse button releases, pointer motions, window entries, and window exits). During grabs the window manager will not receive pointer events either (which means that if the grab is not released the whole GUI will freeze, so be careful!).

The grab command can take any of the following forms:

grab release window
Releases the grab on window if there is one, otherwise does nothing. Returns an empty string.
grab set window
If a grab was already in effect for this application on window's display then it is automatically released. If there is already a grab on window then the command does nothing. Returns an empty string.
grab ifunset window
Same as grab set except that window is only grabbed if there is no other grab currently in effect.
grab status window
Returns none if no grab is currently set on window, or window if it has the grab.


The current application-exclusive nature of grab is a problem which will be adressed in the future.

GRAB(9 ) Rev:  Tue Mar 31 02:42:39 GMT 2015