Teek::App Class
Inherits: Object
Instance Methods ↑
add_package_path(path)
Add a directory to Tcl’s package search path.
Parameters
pathString— directory containing Tcl packages
Returns void
after(ms, &block)
Schedule a one-shot timer. Calls the block after ms milliseconds.
Parameters
msInteger— delay in milliseconds
Returns String — timer ID, pass to #after_cancel to cancel
@yield block to call when the timer fires
after_cancel(after_id)
Cancel a pending #after or #after_idle timer.
Parameters
after_idString— timer ID returned by#afteror#after_idle
Returns void
after_idle(&block)
Schedule a block to run once when the event loop is idle.
Returns String — timer ID, pass to #after_cancel to cancel
@yield block to call when the event loop is idle
appearance
Get the macOS window appearance. No-op (returns nil) on non-macOS.
Returns String, nil — "aqua", "darkaqua", "auto", or nil on non-macOS
Example
app.appearance # => "aqua", "darkaqua", or "auto"
app.appearance = :light # force light mode
app.appearance = :dark # force dark mode
app.appearance = :auto # follow system setting
See also
appearance=(mode)
Set the macOS window appearance. No-op on non-macOS.
Parameters
modeSymbol, String—:light,:dark,:auto, or a raw Tk value
Returns void
bool_to_tcl(val)
Convert a Ruby boolean to a Tcl boolean string (“1” or “0”).
Parameters
valBoolean
Returns String — "1" or "0"
busy(window: '.')
Show a busy cursor on a window while executing a block. The cursor is restored even if the block raises.
Parameters
windowString— Tk window path
Returns — the block's return value
@yield the work to perform while busy
command(cmd, *args, **kwargs)
Build and evaluate a Tcl command from Ruby values.
Positional args are converted: Symbols pass bare, Procs become
callbacks, everything else is brace-quoted. Keyword args become
-key value option pairs.
Parameters
cmdSymbol, String— the Tcl command nameargs— positional argumentskwargs— keyword arguments mapped to-key valuepairs
Returns String — the Tcl result
Example
app.command(:pack, '.btn', side: :left, padx: 10)
# evaluates: pack .btn -side left -padx {10}
create_widget(type, path nil, parent: nil, **kwargs)
Create a Tk widget and return a Widget wrapper.
Auto-generates a unique path if none is given. The path is derived from the widget type and a monotonic counter.
Parameters
typeString, Symbol— Tk widget command (e.g. 'ttk::button', :canvas)pathString, nil— explicit Tk path, or nil for auto-namingparentWidget, String, nil— parent widget for path nestingkwargs— keyword arguments passed to the Tk widget command
Returns Widget — the created widget
Examples
# Auto-named
btn = app.create_widget('ttk::button', text: 'Click')
# btn.path => ".ttkbtn1"
# Explicit path
frm = app.create_widget('ttk::frame', '.myframe')
# Nested under a parent
frm = app.create_widget('ttk::frame')
btn = app.create_widget('ttk::button', parent: frm, text: 'Click')
# btn.path => ".ttkfrm1.ttkbtn1"
dark?
Returns true if the window is currently displayed in dark mode. Always returns false on non-macOS.
Returns Boolean
destroy(widget)
Destroy a widget and all its children.
Parameters
widgetString— Tk widget path (e.g. ".frame1")
Returns void
font_metrics(font)
Get font metrics (ascent, descent, linespace) for a given font. Uses Tk’s C font API directly.
Parameters
fontString— font description (e.g. "Helvetica 12", "TkDefaultFont")
Returns Hash{Symbol => Integer} — :ascent, :descent, :linespace
@raise Teek::TclError if the font is not found
get_variable(name)
Get a Tcl variable’s value.
Parameters
nameString— variable name
Returns String — the value
@raise Teek::TclError if the variable doesn't exist
hide(window '.')
Hide a window without destroying it. Defaults to the root window (“.”).
Parameters
windowString— Tk window path
Returns void
initialize(track_widgets: true, debug: false, &block)
Returns App — a new instance of App
make_list(*args)
Build a properly-escaped Tcl list from Ruby strings.
Parameters
argsArray<String>— elements to join
Returns String — a Tcl-formatted list
measure_chars(font, text, max_pixels, **opts)
Measure how many bytes of text fit within a pixel width limit. Useful for text truncation, ellipsis, and line wrapping.
Parameters
fontString— font description (e.g. "Helvetica 12")textString— text to measuremax_pixelsInteger— maximum pixel width (-1 for unlimited)optsHash— options
Returns Hash{Symbol => Integer} — :bytes and :width
Options
:partial_okBoolean— allow partial character at boundary:whole_wordsBoolean— break only at word boundaries:at_least_oneBoolean— always return at least one character
@raise Teek::TclError if the font is not found
package_names
List all packages known to this interpreter.
Scans auto_path for package indexes before querying.
Returns Array<String>
package_present?(name)
Check if a package is already loaded in this interpreter.
Parameters
nameString— package name
Returns Boolean
package_versions(name)
List available versions of a package.
Scans auto_path for package indexes before querying.
Parameters
nameString— package name
Returns Array<String>
register_callback(callable)
Register a Ruby callable as a Tcl callback.
The callable can use throw for Tcl control flow:
throw :teek_break - stop event propagation (like Tcl “break”)
throw :teek_continue - Tcl TCL_CONTINUE
throw :teek_return - Tcl TCL_RETURN
Parameters
callable#call— a Proc or lambda to invoke from Tcl
Returns Integer — callback ID, usable as ruby_callback <id> in Tcl
See also
require_package(name, version nil)
Load a Tcl package into this interpreter.
Parameters
nameString— package name (e.g. "BWidget")versionString, nil— minimum version constraint
Returns String — the version that was loaded
@raise Teek::TclError if the package is not found
set_variable(name, value)
Set a Tcl variable. Useful for widget textvariable and variable options.
Parameters
nameString— variable namevalueString— value to set
Returns String — the value
set_window_geometry(geometry, window: '.')
Set a window’s geometry (e.g. “400x300”, “400x30010050”).
Parameters
geometryString— geometry stringwindowString— Tk window path
Returns String — the geometry
set_window_resizable(width, height, window: '.')
Set whether a window is resizable.
Parameters
widthBoolean— allow horizontal resizeheightBoolean— allow vertical resizewindowString— Tk window path
Returns void
set_window_title(title, window: '.')
Set a window’s title.
Parameters
titleString— new titlewindowString— Tk window path
Returns String — the title
show(window '.')
Show a window. Defaults to the root window (“.”).
Parameters
windowString— Tk window path
Returns void
split_list(str)
Split a Tcl list string into a Ruby array of strings.
Parameters
strString— a Tcl-formatted list
Returns Array<String>
tcl_eval(script)
Evaluate a raw Tcl script string and return the result.
Prefer #command for building commands from Ruby values; use this
when you need Tcl-level features like variable substitution or
inline expressions that #command can’t express.
Parameters
scriptString— Tcl code to evaluate
Returns String — the Tcl result
tcl_invoke(*args)
Invoke a Tcl command with pre-split arguments (no Tcl parsing).
Safer than #tcl_eval when arguments may contain special characters.
Parameters
argsArray<String>— command name followed by arguments
Returns String — the Tcl result
tcl_to_bool(str)
Convert a Tcl boolean string (“0”, “1”, “yes”, “no”, etc.) to Ruby boolean.
Parameters
strString— a Tcl boolean value
Returns Boolean
text_width(font, text)
Measure the pixel width of a text string in a given font.
Uses Tk’s C font API directly — faster than the Tcl font measure command.
Parameters
fontString— font description (e.g. "Helvetica 12", "TkDefaultFont")textString— text to measure
Returns Integer — pixel width
@raise Teek::TclError if the font is not found
unbind(widget, event)
Remove an event binding previously set with #bind.
Parameters
widgetString— Tk widget path or class tageventString— Tk event name, with or without angle brackets
Returns void
See also
unregister_callback(id)
Remove a previously registered callback by its ID.
Parameters
idInteger— callback ID returned by#register_callback
Returns void
update_idletasks
Process only pending idle callbacks (e.g. geometry redraws), then return.
Returns void
window_geometry(window: '.')
Get a window’s current geometry.
Parameters
windowString— Tk window path
Returns String — geometry string (e.g. "400x30000")
window_resizable(window: '.')
Get whether a window is resizable.
Parameters
windowString— Tk window path
Returns Array(Boolean, Boolean) — [width_resizable, height_resizable]
window_title(window: '.')
Get a window’s current title.
Parameters
windowString— Tk window path
Returns String — current title
Attributes ↑
debugger [R]
Returns the value of attribute debugger.
interp [R]
Returns the value of attribute interp.
widgets [R]
Returns the value of attribute widgets.