Teek::Window Class
A single toplevel window, addressed by its Tk path - the window-scoped
counterpart to Widget (which covers any widget of any type). Groups
every wm subcommand alongside composite window-lifecycle behaviors
(on_close, grab_set/grab_release, modal) that would otherwise keep
growing as more and more window:-kwarg methods flattened onto App
- app.window(path).thing reads better than threading window:
through a dozen unrelated top-level methods, and gives callers (like
teek-ui’s DSL) one coherent object per window instead of loose parts.
App#wm (Wm) and App’s own window_title/set_window_title/etc.
convenience methods, plus App#on_close/#grab_set/#grab_release/
#modal, all delegate here internally - nothing about those public
methods changed, this is where their actual work happens now.
Inherits: Object
Instance Methods ↑
geometry
Returns String — geometry string (e.g. "400x30000")
grab_release
Release a grab previously set with #grab_set. Safe to call even if
the window never held the grab - Tk itself treats that as a no-op.
Returns void
grab_set(global: false)
Set the input grab on the window - while held, mouse and keyboard
events outside it (and its descendants) are redirected to it, the
building block #modal uses. grab is its own Tcl command family,
separate from wm.
Parameters
globalBoolean— a global grab blocks input to every other application too, not just this one - almost never what you want; local (the default) is scoped to this application.
Returns void
See also
modal(global: false)
Make the window modal: grabs input and sets focus on it immediately.
Release it explicitly with #grab_release (typically from the
window’s own dismiss/close handling) when the dialog is done - the
grab is NOT released automatically just because this method returns,
since a modal dialog is meant to stay grabbed for its whole visible
lifetime, not just its setup.
Two safety nets guard against a stuck grab locking out the rest of
the display: if the window is destroyed while still grabbed (a crash
mid-modal, or just forgetting to call #grab_release first), a
Parameters
globalBoolean— see#grab_set
Returns void
@yield optional - runs with the grab and focus already set
Example
settings = app.window(settings_path)
settings.modal { settings.deiconify }
# ... later, from the window's own on_close/dismiss handler ...
settings.grab_release
See also
on_close(&block)
Register a handler for the window manager’s close button (WM_DELETE_WINDOW - the titlebar close box, Cmd-W, Alt-F4, etc., depending on platform).
Tk’s own default behavior (destroy the window) only applies when
nothing else has claimed this protocol - setting a handler here
replaces it, so the block is entirely responsible for deciding
whether the window actually closes. Call App#destroy yourself if
you want it to; do nothing (or show a confirmation first) if you don’t.
Returns void
@yield called when the window's close button is pressed
Examples
# Confirm before quitting
app.window.on_close { app.destroy('.') if app.message_box(message: 'Quit?', type: :yesno) == :yes }
# A toplevel that just hides instead of closing
app.window(settings_window).on_close { app.window(settings_window).withdraw }
See also
resizable
Returns Array(Boolean, Boolean) — [width_resizable, height_resizable]
set_geometry(value)
Parameters
valueString— new geometry (e.g."400x300","400x30010050")
Returns String — the geometry
set_resizable(width, height)
Parameters
widthBoolean— allow horizontal resizeheightBoolean— allow vertical resize
Returns void
title
Returns String — the window's current title
to_s
Returns String — the Tk window path
Attributes ↑
path [R]
Returns the value of attribute path.