Name

grab

grab operation [arg arg...]

The grab command implements simple pointer and keyboard grabs. Tk restricts all pointer events to the grab window and its descendants (which may include top-level windows). Pointer events outside the grab window’s tree are reported as events to the grab window. No window entry or window exit events are reported to the grab window. A grab applies only to the display of the grab window.

Two types of grabs are possible: local and global. A local grab, the default, affects only the grabbing application, so events are reported normally to other applications on the display. A global grab blocks events to all other applications on the display so that only the specified subtree of the grabbing application will receive pointer events.

The grab command can take the following forms:

grab [-global] window

Same as grab set.

grab current [window]

Return the name of the application’s current grab window on window’s display, or an empty string if there is no such window. If window is not given, a list of all windows grabbed by this application for all displays is returned.

grab release window

Release the grab on window if there is one.

grab set [-global] window

Set a grab on window. If -global is specified, the grab will be global. Any other grab by the application on window’s display is released.

grab status window

Return none, local, or global to describe the grab currently set on window.

Get Tcl/Tk in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.