Grab
This capability documents one focused aspect of the widget interface (Tk/Tcl-style behavior + bootstack extensions).
Note: You typically won’t use
bootstack.core.capabilities.grabdirectly. This page describes the behavior that widgets expose.
Pointer/keyboard grab helpers (grab).
A grab confines mouse and keyboard events to a particular widget subtree.
When a grab is active
- Pointer events are delivered only to the grab window and its descendants.
- Keyboard events are also directed to the grab window (effectively focusing input).
- This is the foundation for modal interactions (e.g., modal dialogs).
Tk supports two kinds of grabs
- Local (application) grab: confines events within the current Tk application.
- Global grab: confines events at the window system level (more intrusive).
Notes
- Grabs should be released when you are done (typically in a
finally:block). - Global grabs can make the entire desktop feel “stuck” if misused; prefer local grabs unless you specifically need global behavior.
- A grab does not automatically make a window modal; typical modal patterns also:
transient(parent),focus_set(), andwait_window()/wait_visibility().
grab_set
grab_set() -> None
Set a local (application) grab on this widget.
With a local grab, events are confined within the current Tk application. This is the preferred grab type for modal dialogs inside an application.
grab_set_global
grab_set_global() -> None
Set a global grab on this widget.
A global grab confines events at the window system level. This is more intrusive than a local grab and should be used with care.
grab_release
grab_release() -> None
Release a grab held by this widget (if any).
grab_current
grab_current() -> Any
Return the widget in this application that currently holds the grab.
Returns:
| Type | Description |
|---|---|
Any
|
The widget instance that currently holds the grab, or None if no grab is held by this application. |
grab_status
grab_status() -> str | None
Return the grab status for this widget.
Returns:
| Type | Description |
|---|---|
str | None
|
The grab status: "local" if this widget holds a local grab, "global" if this widget holds a global grab, or None if this widget does not hold the grab. |