Skip to content

Python API

A quick reference to everything import tess_re gives you: each class with its properties, methods and events, short descriptions, and what it inherits. The Rust API is what these classes sit on. The Details link on a class goes to its longer page (behavior, examples, edge cases).

Node and Window take most of their properties by name through set, get and (for the animatable ones) animate, and their events by name through on; those names are listed with the class. None of these classes is meant to be subclassed.

Class Purpose
App Opens and drives one or more windows together in one blocking run().
LoopHandle The one thread-safe object: queues a callable onto a running App's loop.
StatsHandle Reads a window's frame statistics from any thread, without waiting for the loop.
TimerHandle Cancels a timer set with Window.after or Window.every.
Window Owns a node tree and its size and title; creates nodes, shows layers, docks panels.
LayerWindow A window the compositor places: a bar, panel, dock or OSD (a Wayland layer surface).
PopupWindow A menu or flyout the compositor places beside a rectangle of its parent (a Wayland xdg_popup).
Output A screen the compositor has: its connector name, position, size, scale and rotation.
Node A handle to one node in a window's tree: properties, animation, events, structure.
Event What a listener receives when it takes one argument; never constructed directly.
Painter The drawing surface a canvas node's draw callback receives.
Gradient A linear, radial or sweep gradient to give a box as its fill.
CursorImage A pointer shape drawn from pixels, for a node's cursor.
Shader WGSL that paints a node (a fill) or transforms its rendered content (an effect).
ShaderError A shader's source or names are wrong, positioned in the WGSL you gave.
UnsupportedPlatform Raised where a feature needs a platform this process is not on (a LayerWindow without a layer shell).

App

Opens and drives one or more windows together in one blocking run().

Inherits: object · Details: App reference

Constructor: App(scheme: Literal['light', 'dark', 'auto'] | None=None)

Methods:

Method Description
add_window(window: Window) -> None Adds a window to open when run() is called.
clear_defaults(kind: str \| None=None) -> None Removes the app's defaults for kind, or all of them.
get(name: Literal['scheme']) -> Literal['light', 'dark', 'auto'] Reads scheme.
get_defaults(kind: str \| None=None) -> dict[str, Any] The app's defaults: {property: value} for kind, or {kind: {property: value}} for all.
off(event: Literal['output_added', 'output_removed', 'output_updated', 'connection_lost']) -> None Removes the handler for an output event or for "connection_lost".
on(event, handler) -> None Registers handler(output) for a screen being plugged in, removed, or moved, resized, rescaled or rotated.
outputs() -> list[Output] The screens the compositor has, top to bottom and left to right, read now (so it works before run()).
run(max_frames: int \| None=None, keep_alive: bool=False) -> None Opens every added window and runs the event loop until they all close, or max_frames.
set(*, scheme: Literal['light', 'dark', 'auto']=...) -> None Sets scheme, live: every window that sets none of its own repaints in it.
set_defaults(kind: str \| Mapping[str, Mapping[str, Any]], **props: Any) -> None Window.set_defaults for every window of this app: the baseline look of the nodes its windows create afterwards, unless the…
simulate(event: Literal['output_added', 'output_removed', 'output_updated'], **fields: Any) -> None Delivers an output event as the compositor would, for tests with no display: `app.simulate("output_added", name="DP-2"…
thread_handle() -> LoopHandle A thread-safe handle to this App's event loop.

Events: none.

LoopHandle

The one thread-safe object: queues a callable onto a running App's loop.

Inherits: object · Details: Threading guide

Methods:

Method Description
call_soon(callback: Callable[[], object]) -> None Queues callback (called with no arguments) to run on the App's event-loop thread, and wakes the loop.
stop() -> bool Ends the running loop, from any thread.

Events: none.

StatsHandle

Reads a window's frame statistics from any thread, without waiting for the loop.

Inherits: object · Details: StatsHandle reference

Methods:

Method Description
read(reset: bool=False) -> dict[str, Any] The dict Window.frame_stats() returns, except that profile is always None (it names Nodes, which belong to the loop's…

Events: none.

TimerHandle

Cancels a timer set with Window.after or Window.every.

Inherits: object · Details: TimerHandle reference

Properties:

Property Type Description
active bool Whether the timer is still pending: an every until cancelled, an after until it has run.

Methods:

Method Description
cancel() -> bool Stops the timer.

Events: none.

Window

Owns a node tree and its size and title; creates nodes, shows layers, docks panels.

Inherits: object · Details: Window reference

Constructor: Window(width: int=480, height: int=200, title: str='tess_re v2', decorations: bool=True, scheme: Literal['light', 'dark', 'auto'] | None=None, first_present: Literal['immediate', 'on_ready'] | int | None=None, background: tuple[int, int, int, int] | None=None)

Properties:

Property Type Description
root Node The window's root node — a flex row with 16px padding and gaps, sized to the window.

Settable and readable properties (window.set(...), window.get(name)):

Property Access Description
width, height get The client area's size (change it with resize).
title set, get The window title, live if open.
scale_factor get Display scale; 1.0 until App.run() opens the window.
dark get The OS appearance: True, False, or None when it can't say.
partial_redraw, partial_redraw_active set, get Redraw only what changed; whether that is in effect.
show_damage set, get Tint what each frame redrew.
decorations set, get Whether the OS draws the title bar and borders.
fullscreen set, get Borderless fullscreen.
min_width, min_height set, get The smallest size the user can resize to.
icon set (rgba, width, height) or None.
maximized, minimized, active get Window state; use the methods to change it.
platform get "wayland", "x11", "windows" or "macos".
resize_border, system_menu set, get Border width for undecorated windows; the OS window menu.
titlebar_inset, native_controls get macOS traffic-light area; whether the OS shows its controls.
gpu_watchdog set, get Seconds before a stuck frame fires gpu_stalled; None is off.
present_mode set, get "vsync" (default) paces frames to the display; "low_latency" shows the newest frame at once.
dpi_scaling set, get Layout in logical pixels, drawn at the display's scale (0.5.4); off by default.
glyph_cache set, get Draw text from the glyph cache: about 4x cheaper, edge pixels differ slightly (0.5.4); off by default.
profile_nodes set, get Time each node the paint walk reaches, for frame_stats() (0.5.4).
transparent, transparent_active set, get / get A see-through window background, and whether it took effect (0.5.4).
blur_behind, click_through set, get Ask the compositor to blur behind a transparent window; ignore the pointer entirely (0.5.4).
reduced_motion, high_contrast get The OS's motion and contrast preferences (0.5.4).

Methods:

Method Description
add_dock_zone(side: str, container: Node, size: float) -> None Registers container as the dock zone for side.
advance(ms: float) -> None Moves the window's clock forward by ms, running animations, callbacks and layout.
after(ms: float, fn: Callable[[], object]) -> TimerHandle Calls fn once, ms milliseconds from now, on the loop's thread.
announce(text: str, politeness: str='polite') -> None (0.6.9, TRE-REQ-021) Raises one live announcement for this window through the accessibility tree, with no node of yours: a…
apply(changes: Sequence[tuple[Node, dict[str, Any]]]) -> None Changes properties on many nodes in one call: a sequence of (node, props) pairs, each props what node.set(**props) takes.
build(spec: dict[str, Any]) -> tuple[Node, dict[str, Node]] Makes a whole detached subtree from one nested description and returns (root, nodes): the root and a dict of every node that…
center() -> bool Centres the open window on its monitor.
clear_defaults(kind: str \| None=None) -> None Removes this window's defaults for kind, or all of them.
close() -> None Closes the window as if the user had: close_requested fires first, and a listener that cancels it keeps the window open.
create(kind: str, **props: Any) -> Node Makes a detached node of a kind; attach it with add_child.
dock_panel(side: str, panel: Node) -> None Docks panel into side's zone and shows it.
every(ms: float, fn: Callable[[], object]) -> TimerHandle Calls fn every ms milliseconds (at least 1) until the handle is cancelled.
frame_stats(reset: bool=False) -> dict[str, Any] What this window's frames cost, as a dict: frames (drawn since the window opened), skipped (passes that found nothing to…
get_defaults(kind: str \| None=None) -> dict[str, Any] This window's own defaults (not its app's): {property: value} for kind (empty when none), or {kind: {property: value}} for…
hide_layer(node: Node) -> None Hides a layer, detaching it, and returns focus to where it was.
maximize() -> None Maximizes the window — or opens it maximized.
measure_text(text, font_family, font_size, font_weight, font_style, letter_spacing, line_height, max_width, wrap, max_lines, overflow) -> tuple[float, float] Returns the (width, height) a text node with these properties would take.
minimize() -> None Minimizes the window — or, before App.run(), opens it minimized.
off(event: str) -> None Removes the window's listener for event, if any.
on(event: str, handler: Callable[..., object]) -> None Registers handler for a window event.
read_clipboard() -> str \| None Returns the OS clipboard's text, or None when there is none or it can't be reached.
ready() -> None Tells a window made with first_present="on_ready" (or a deadline) that its first frame is complete: it is presented, and the…
request_activation_token(callback: Callable[[str \| None], object], app_id: str \| None=None) -> None Asks the system for an activation token (xdg_activation_v1 on Wayland, a startup-notification id on X11) and calls…
resize(width: int, height: int) -> None Sets the window's size from code; the root's layout box follows.
restore() -> None Restores a minimized or maximized window to its normal size; before App.run(), undoes minimize()/maximize().
set(*, title, partial_redraw, show_damage, profile_nodes, glyph_cache, decorations, fullscreen, min_width, min_height, icon, resize_border, system_menu, titlebar_double_click, resize_cursors, undecorated_shadow, gpu_watchdog, present_mode, dpi_scaling, transparent, blur_behind, click_through, x, y, always_on_top, resizable, skip_taskbar, touch_slop, touch_target_slop, gesture_long_press_ms, gesture_tap_ms, gesture_double_tap_ms, gesture_double_tap_px, gesture_swipe_speed, gesture_swipe_px, gesture_rotate_slop, multi_click_ms, multi_click_px, drag_start_px, pause_when_occluded, reduced_motion, scheme, scheme_colors, background, layer_viewport_margin, layer_flip_threshold, ime_offset) -> None Sets window properties by name, all at once; a bad value raises and changes nothing.
set_active_panel(side: str, index: int) -> None Shows the indexth panel docked in side's zone (was set_active_tab).
set_defaults(kind: str \| Mapping[str, Mapping[str, Any]], **props: Any) -> None Declares the baseline look of the nodes this window creates afterwards, once, so create and build need not repeat it.
show_layer(node, anchor, placement, modal, dismissible, offset, flip, viewport_margin, flip_threshold, align, shift) -> None Shows node over the window's content, above every layer already open.
simulate(event: str, node: Node \| None=None, **fields: Any) -> None Delivers a synthetic event as real input would, for tests with no display.
snapshot(width, height, scale, time) -> tuple[bytes, int, int] What the window draws, as (rgba, width, height): straight-alpha RGBA8 bytes, width * height * 4 of them, top row first.
start_panel_drag(panel: Node) -> None Starts dragging panel, a docked panel.
start_trace(path: str) -> None Writes every frame this window draws from now on to path as a Chrome / Perfetto trace (open it at ui.perfetto.dev or…
stats_handle() -> StatsHandle A handle any thread can use to read this window's frame statistics (handle.read()) without waiting for the event loop.
stop_trace() -> int Closes the trace start_trace opened and returns how many frames it holds (0 if none is running).
undock_panel(panel: Node) -> None Takes panel out of docking.
write_clipboard(text: str) -> bool Puts text on the OS clipboard; False when it can't be reached (logged, never raised).

Events (window.on(event, handler); a window event has no node):

Event Payload Fires when
resize width, height The client area changed size.
color_scheme dark The OS switched between light and dark.
scale_factor scale_factor The window moved to a display with a different scale.
close_requested — The user asked to close; event.cancel() keeps it open.
closed reason (a LayerWindow) The window closed.
configure, output_changed, warning width, height / output / key, message A LayerWindow: the compositor sized it / it entered an output / a setting the protocol ignores.
moved margin A LayerWindow: a window_region="drag_margin" drag ended; the final (top, right, bottom, left).
dock_target, dock_drop side, panel A docking drag moved into a zone / ended.
maximized, active maximized, active The window was maximized or restored / gained or lost focus.
titlebar_inset titlebar_inset The OS controls' area over the content changed.
gpu_lost reason, message The GPU was lost; the run is ending.
gpu_error message The GPU reported an error; the draw was skipped.
gpu_stalled seconds A submitted frame has not completed after gpu_watchdog seconds.
file_hover, file_hover_cancel, file_drop paths, path Files dragged over, away from, or dropped on the window (0.5.4).
reduced_motion, high_contrast reduced_motion, high_contrast The OS's motion or contrast preference changed (0.5.4).
frame stats A frame was drawn and presented; stats holds its costs (0.5.4).

LayerWindow

A window the compositor places: a bar, panel, dock or OSD (a Wayland layer surface).

Inherits: Window → object · Details: LayerWindow reference

Constructor: LayerWindow(namespace: str, *, layer: Literal['background', 'bottom', 'top', 'overlay']=..., anchor: str | Sequence[str] | None=..., size: tuple[int | Literal['content'], int | Literal['content']] | None=..., min_size: tuple[int | None, int | None] | None=..., max_size: tuple[int | None, int | None] | None=..., exclusive_zone: int | None=..., exclusive_edge: Literal['top', 'bottom', 'left', 'right'] | None=..., margin: int | tuple[int, int, int, int] | None=..., keyboard: Literal['none', 'on_demand', 'exclusive']=..., output: str | Output | None=..., input_region: Literal['auto'] | Sequence[tuple[float, float, float, float]] | None=..., click_through: bool | None=..., scheme: Literal['light', 'dark', 'auto'] | None=..., first_present: Literal['immediate', 'on_ready'] | int | None=..., background: tuple[int, int, int, int] | None=...)

Methods:

Method Description
animate(property, to, duration_ms, easing, on_complete) -> None Moves one margin to to pixels from where it is now, in the engine: one small commit per step and no Python until on_complete…
close() -> None Closes the surface on the loop's next turn: close_requested first (a listener may cancel it with event.cancel()), then…
get(name: str) -> Any Reads a layer setting (namespace, layer, anchor, size, exclusive_zone, exclusive_edge, margin, keyboard…
set(**props: Any) -> None Sets properties; the layer ones (layer, anchor, size, exclusive_zone, margin, keyboard, input_region…

Events: none.

A menu or flyout the compositor places beside a rectangle of its parent (a Wayland xdg_popup).

Inherits: Window → object · Details: PopupWindow reference

Constructor: PopupWindow(parent: LayerWindow | PopupWindow, *, size: tuple[int, int], anchor_rect: tuple[int, int, int, int], anchor: Literal['none', 'top', 'bottom', 'left', 'right', 'top_left', 'bottom_left', 'top_right', 'bottom_right']=..., gravity: Literal['none', 'top', 'bottom', 'left', 'right', 'top_left', 'bottom_left', 'top_right', 'bottom_right']=..., constraint_adjustment: str | Sequence[str] | None=..., offset: tuple[int, int] | None=..., grab: bool=..., geometry: tuple[int, int, int, int] | None=..., edge_margin: int | tuple[int, int, int, int] | None=..., input_region: Sequence[Sequence[float]] | Literal['geometry'] | None=..., scheme: Literal['light', 'dark', 'auto'] | None=..., first_present: Literal['immediate', 'on_ready'] | int | None=..., background: tuple[int, int, int, int] | None=...)

Methods:

Method Description
close() -> None Closes the popup on the loop's next turn: close_requested first, then closed with reason "app".
get(name: str) -> Any Reads size, anchor_rect, anchor, gravity, constraint_adjustment, offset, grab, geometry (the body; the whole…
set(**props: Any) -> None Sets input_region and the window keys a popup shares (touch_slop, partial_redraw, ...).

Events: none.

Output

A screen the compositor has: its connector name, position, size, scale and rotation.

Inherits: object · Details: Output reference

Properties:

Property Type Description
name str The connector name ("DP-1", "HDMI-A-1"): stable across runs.
description str The compositor's description (make, model, serial).
x int The output's left edge in the desktop's logical layout.
y int The output's top edge in the desktop's logical layout.
width int The logical width, in pixels.
height int The logical height, in pixels.
scale_factor float Physical over logical pixels: 1.5 on a 1.5x output.
transform str "normal", "90", "180", "270", or one of those after "flipped_".

Events: none.

Node

A handle to one node in a window's tree: properties, animation, events, structure.

Inherits: object · Details: Node reference

Kinds (window.create(kind, **props)):

Kind Required What it is
"box" — A layout container with fill, stroke, corners and shadows.
"text" text Shaped, non-editable text.
"text_input" — Editable text: selection, clipboard, IME, obscuring.
"image" rgba, pixel_width, pixel_height RGBA8 pixels; video is repeated set(rgba=…).
"path" data A vector path.
"canvas" draw Immediate-mode drawing through a Painter.
"scroll_view" — Clips and scrolls one child.
"virtual_list" item_count, materialize Builds only the rows its viewport shows.
"terminal" shell, cols, rows A PTY-backed terminal emulator.
"svg" svg, svg_color, svg_images A whole SVG document, fitted into the node's box (0.5.4).

Settable properties (node.set(...), node.get(name); node.animate(...) for the animatable ones):

Size and position

Property Value Description
width, height, min_width, min_height, max_width, max_height pixels, "auto", or "50%" Box size and limits.
aspect_ratio number or None Width over height.
position "relative" or "absolute" In the flow, or placed by x/y.
x, y pixels, percentage, "auto" Left and top offset.

Flex layout

Property Value Description
flex_direction "horizontal" or "vertical" Main axis.
flex_wrap "no_wrap" or "wrap" Whether children wrap.
align_items, justify_content alignment names Cross- and main-axis alignment of children.
gap pixels or percentage Space between children.
padding, padding_top/_right/_bottom/_left pixels or percentage Inset; a node's own content draws inside it.
flex_grow, flex_shrink, flex_basis numbers / like width How a flex child grows, shrinks and starts.
align_self an align_items value or None Overrides the parent's alignment for this child.
margin, margin_top/_right/_bottom/_left pixels, percentage, "auto" Outer space.

Grid layout

Property Value Description
display "flex" or "grid" Which layout a node's children use.
grid_template_columns, grid_template_rows track list The grid's tracks.
grid_auto_columns, grid_auto_rows, grid_auto_flow track list / flow name Implicit tracks and auto-placement.
row_gap, column_gap pixels or percentage Space between rows or columns.
justify_items, align_content, justify_self alignment names Cell and track alignment.
grid_column, grid_row line, "span 2", "1 / 3" A grid child's placement.

Transform, visibility and order

Property Value Description
translate_x, translate_y pixels (animatable) Offset from the laid-out position.
scale, rotation_deg number (animatable) Scale and clockwise rotation about transform_origin (the center by default).
transform_origin (x, y) The point scale and rotation_deg turn about, as fractions of the box; default (0.5, 0.5). Not animatable (0.6.4).
visible bool False hides the node and its subtree.
z_index int Paint and hit order among siblings.
clip_children bool Clips children to the rounded box.
cursor cursor name or None Pointer shape over the node.
hit_testable bool or None Whether the node can be a pointer target. None (default) is every kind, a text label included (0.6.11); False makes it transparent to the pointer.
hit_shape "box", "painted" (path only) Whether a path is hit by its box or by what it paints.
hit_path SVG path data, or None The shape, in the node's own pixels, that clicks and an auto input region follow in place of the box (0.6.4).
window_region "drag", "none", None Makes a node a title bar that moves the window.

Paint (every kind)

Property Value Description
fill (r, g, b, a) (animatable) Background; glyph color on text; a path's fill.
stroke_color, stroke_width color / pixels (animatable) Border inside the box; a path's outline.
corner_radius number or 4-tuple (animatable) Rounds background, border and image.
corner_style "round" or "concave", or a 4-tuple of them A concave corner curves inward about the box's corner, with the corner's radius (0.6.4).
opacity 0.0–1.0 (animatable) Group opacity of the node and its subtree.
shadows list of (color, dx, dy, blur, spread) CSS box-shadow model.
shader Shader or None WGSL that paints or transforms the node.

Text and text input

Property Value Description
text str The content (read-only on a terminal).
font_family, font_weight, font_size name / 1–1000 / pixels Font.
line_height, text_align, font_style, letter_spacing, wrap, max_lines, overflow see the text guide Text layout (text nodes; line_height and letter_spacing on text_input too, 0.6.11).
vertical_align "start", "center", "end" Where the lines sit in the content box (text, text_input; 0.6.11).
multiline, selection, show_whitespace, syntax_spans, folded_ranges — Text input editing and decoration.
tab_navigates (text input) bool Tab and Shift+Tab move focus out of a multiline input instead of typing a tab character (0.6.8). Off by default.
overwrite (text input) bool Overwrite mode: a typed character replaces the one after the caret; Insert toggles it (0.6.7).
wrap, overflow (text input) "word"/"none"; "scroll"/"ellipsis"/"clip"; or None How a text input shows a long line: wrap for a multiline input, overflow for a single-line one; None is as before (0.6.6).
placeholder, placeholder_fill, caret_color, selection_fill, obscured — Text input colors and password mode.

Image, path and canvas

Property Value Description
rgba, pixel_width, pixel_height, fit bytes / ints / "fill", "contain", "cover" Image pixels and how they fit the box.
params dict of name to number (path only) The numbers a path template (data with {expression} holes) reads; animate_param(name, to, duration_ms, easing) animates one (0.6.4).
morph "resample", "structure", "strict" (path only) How an animation of data morphs: resample (default), by matching commands, or by matching commands or raise (0.6.4).
data, view_box, trim_start, trim_end SVG path / tuple / 0.0–1.0 A path's shape, viewport and drawn part.
svg_time, svg_duration seconds / read-only seconds or None An svg's position in its SMIL animation, and how long that runs (0.5.10).
draw draw(painter) A canvas's drawing callback.

Scrolling, lists and terminals

Property Value Description
orientation, scroll_offset, scroll_offset_x, scrollbar_fill, scrollbar_width — A scroll view's direction ("vertical", "horizontal" or, 0.6.11, "both"), positions and bar.
scrollbar_hit_width, scrollbar_margin, scrollbar_min_length, scrollbar_gutter, scrollbar_corner, scrollbar_opacity, scrollbar_opacity_hover, scrollbar_opacity_drag number or None The rest of a scroll view's scrollbar (0.6.11); the defaults of a "both" view are the Tesserae UX spec's.
item_count, item_extent, size_hint, materialize — A virtual list's rows.
cols, rows, shell, scrollback_lines, palette — A terminal's grid, process and colors.

Accessibility and focus

Property Value Description
role, label, value, value_min, value_max, value_step — What assistive technology reads.
checked, selected, expanded, disabled, level, live, a11y_hidden — State announced to assistive technology.
focusable, tab_index bool / int Whether and where Tab reaches the node.

Read-only

Property Value Description
kind, focused, layer_placement — The node's kind, focus state, and a shown layer's side.
layout_x, layout_y, layout_width, layout_height pixels Where the node is, as laid out (runs pending layout).

Methods:

Method Description
add_child(child: Node) -> None Appends child under this node, moving it if it's attached elsewhere.
animate(property, to, duration_ms, easing, on_complete) -> None Eases a property from its current value to a target, retargeting mid-flight.
animate_param(name, to, duration_ms, easing) -> None Moves one parameter of a path's template to a number over duration_ms, from where it is now, like animate; easing as…
capture_pointer() -> None Routes every later pointer event to this node until the button is released or release_pointer() is called.
caret_rect() -> tuple[float, float, float, float] A text input's caret as (x, y, width, height) in the node's coordinates, padding and scrolling included; at the end of the…
children() -> list[Node] This node's children, in order.
destroy() -> None Frees this node and its whole subtree now, with their listeners; focus inside it gets unfocus first.
focus() -> None Moves keyboard focus to this node, firing unfocus/focus.
get(name: str) -> Any Reads one property: any property set accepts.
get_target(name: str) -> Any The value name's running animation is heading to.
insert_child(index: int, child: Node) -> None Attaches child at index, moving it if it is attached elsewhere.
off(event: str) -> None Removes this node's listener for event, if any.
on(event: str, handler: Callable[..., object]) -> None Registers handler for event, replacing any earlier listener for it.
parent() -> Node \| None This node's parent, or None for the root or a detached node.
redraw() -> None Runs this canvas's draw callback now, replacing what it shows with what the callback draws.
release_pointer() -> None Ends this node's pointer capture, if it holds it.
remove() -> None Detaches this node from its parent.
scroll_into_view() -> None Scrolls every scroll view around this node just enough to show it, innermost first, at once.
scroll_to_index(index: int, align: str='nearest') -> bool Scrolls this virtual list so row index shows, whether or not it is built, at once.
set(**props: Any) -> None Sets properties atomically: every value is checked first, and a bad one raises ValueError without changing anything.
set_children(children: Sequence[Node]) -> None Makes children this node's whole content, in that order, in one call.
stop_animation(name: str) -> None Stops name's running animation where it is.
text_rects(start: int, end: int) -> list[tuple[float, float, float, float]] The rectangles covering bytes start..end of a text input's text, one per line, as (x, y, width, height) in the node's…

Events (node.on(event, handler); a bubbling event runs the target's listener, then each ancestor's):

Event Bubbles Fires when
pointer_enter, pointer_leave no The pointer enters or leaves the node's subtree.
pointer_down, pointer_move, pointer_up yes A button is pressed, the pointer moves, a button is released.
pointer_cancel yes The OS took a press (window move, maximize, menu); no pointer_up follows.
click, secondary_click yes Primary or secondary press and release on the same node, or keyboard activation.
wheel yes A wheel or trackpad scroll.
key_down, key_up yes A key is pressed or released while the node or a descendant has focus.
input yes Committed text arrives for the focused text input.
focus, unfocus yes A node gains or loses keyboard focus.
change no A text input's text was changed by the user.
scroll no A scroll view's offset changed, once a frame.
dismiss no An outside press or Escape asked a layer to close.
a11y_action yes Assistive technology asked for an action (increment, expand, set value…).
touch_start, touch_move, touch_end, touch_cancel yes A finger touches, moves, lifts or is taken away (0.5.4); pointer_id.
tap, long_press yes A quick touch and release in place (count), or one held half a second (0.5.4).
pan, pinch yes A dragging or pinching gesture (0.5.4); phase, deltas, scale.
file_hover, file_hover_cancel, file_drop yes Files dragged from the OS over, away from, or dropped on the node (0.5.4); paths.
link yes A click on a text span that has a link (0.5.4); href.

Event

What a listener receives when it takes one argument; never constructed directly.

Inherits: object · Details: Event reference

Properties (each is None when the event has nothing to say about it):

Property Type Description
button str \| None "primary", "secondary", "middle", "back" or "forward".
old_value Any \| None The previous text (change) or offset (scroll).
new_value Any \| None The new text (change) or offset (scroll).
type str The event's name; on every event.
target Node \| None The node the event happened on; every node event.
current Node \| None The node whose listener is running.
x float \| None Pointer position, local to current.
y float \| None Pointer position, local to current.
window_x float \| None Pointer position in the window.
window_y float \| None Pointer position in the window.
delta_x float \| None Wheel scroll in pixels, positive right.
delta_y float \| None Wheel scroll in pixels, positive down.
key str \| None A snake_case key name, or the produced character.
repeat bool \| None Whether a key event is an auto-repeat.
shift bool \| None Modifier held during pointer, wheel, key and click events.
ctrl bool \| None Modifier held during pointer, wheel, key and click events.
alt bool \| None Modifier held during pointer, wheel, key and click events.
meta bool \| None Modifier held during pointer, wheel, key and click events.
text str \| None The committed text of an input event.
action str \| None The requested action of an a11y_action.
value Any \| None The value of an a11y_action such as set_value.
width float \| None New size on resize.
height float \| None New size on resize.
dark bool \| None New appearance on color_scheme.
stats dict[str, Any] \| None
reduced_motion bool \| None
high_contrast bool \| None
maximized bool \| None New state on maximized.
active bool \| None New state on active.
occluded bool \| None New state on occluded.
titlebar_inset tuple[float, float] \| None New (height, width) on titlebar_inset.
reason str \| None "unknown" or "destroyed" on gpu_lost.
message str \| None The driver's or GPU's message on gpu_lost and gpu_error.
seconds float \| None How long the frame has run on gpu_stalled.
scale_factor float \| None New scale on scale_factor.
related_target Node \| None The node on the other side of a focus / unfocus move.
focus_visible bool \| None Whether focus arrived by keyboard.
side str \| None The dock zone under the pointer, or None.
path str \| None
paths list[str] \| None
href str \| None
preedit_cursor tuple[int, int] \| None
caret tuple[float, float, float, float] \| None
inserted tuple[int, int] \| None
property str \| None
finished bool \| None
pointer_id int \| None
phase str \| None
count int \| None
selection list[int] \| list[Node] \| None
ranges list[tuple[int, int]] \| None
anchor int \| Node \| None
selection_source str \| None
scale float \| None
scale_delta float \| None
rotation float \| None
rotation_delta float \| None
direction str \| None
output str \| None
margin tuple[int, int, int, int] \| None
total_x float \| None
total_y float \| None
velocity_x float \| None
velocity_y float \| None
panel Node \| None The dragged panel on dock_drop.

Methods:

Method Description
cancel() -> None Keeps a window open: prevents close_requested's default.
stop() -> None Ends propagation: no listener on a further ancestor runs.

Events: this is what the events above deliver. stop() ends propagation; cancel() keeps a window open on close_requested.

Painter

The drawing surface a canvas node's draw callback receives.

Inherits: object · Details: Painter reference

Methods:

Method Description
fill_circle(cx: float, cy: float, radius: float, color: Color \| Gradient) -> None Fills a circle in canvas-local coordinates.
fill_rect(x: float, y: float, width: float, height: float, color: Color \| Gradient) -> None Fills a rectangle in canvas-local coordinates.
set_hit_test_circle(cx: float, cy: float, radius: float) -> None Replaces this canvas's default rectangular hit test with a circular one.
set_hit_test_path(points: Sequence[Sequence[float]], tolerance: float) -> None Replaces this canvas's default rectangular hit test with a stroke-shaped one.
stroke_path(points: Sequence[Sequence[float]], color: Color \| Gradient, width: float) -> None Strokes a path in canvas-local coordinates.

Events: none.

Gradient

A linear, radial or sweep gradient to give a box as its fill.

Inherits: object · Details: Gradient reference

Properties:

Property Type Description
kind str "linear", "radial" or "sweep".
stops list[tuple[float, Color]]
angle float \| None
center tuple[float, float] \| None
radius float \| None
start float \| None
repeat float How many times the ramp runs across the span; 1.0 is one pass.
spread Literal['pad', 'repeat', 'reflect'] What a pass after the first does.

Methods:

Method Description
linear(stops, angle, repeat, spread) -> Gradient Along a line through the box's centre at angle degrees (0 up, 90 right, 180 down), spanning the box.
radial(stops, center, radius, repeat, spread) -> Gradient Outward from center (fractions of the box; None is (0.5, 0.5), the middle).
sweep(stops, center, start, repeat, spread) -> Gradient Around center (None is the middle), starting start degrees clockwise from up.

Events: none.

CursorImage

A pointer shape drawn from pixels, for a node's cursor.

Inherits: object · Details: CursorImage reference

Constructor: CursorImage(rgba: bytes, width: int, height: int, hotspot: tuple[int, int]=...)

Properties:

Property Type Description
size tuple[int, int]
hotspot tuple[int, int]
ready bool Whether the OS cursor has been made.

Events: none.

Shader

WGSL that paints a node (a fill) or transforms its rendered content (an effect).

Inherits: object · Details: Shader reference

Constructor: Shader(wgsl: str, uniforms: dict[str, float | tuple[float, ...]] | None=None, inputs: dict[str, Node] | None=None, mode: str='fill', animated: bool=False)

Properties:

Property Type Description
wgsl str The WGSL source, as given.
mode str "fill" or "effect".
animated bool Whether the node is repainted every frame.
uniforms dict[str, float \| tuple[float, ...]] The uniforms and their current values, as a new dict.
inputs dict[str, Node] The input nodes by name, as a new dict.

Methods:

Method Description
animate(name, to, duration_ms, easing) -> None Moves uniform name to to over duration_ms, from where it is now, like Node.animate: a number for a number uniform, 2 to…
filter(*, saturate, brightness, contrast, grayscale, hue_rotate, invert, sepia) -> Shader A ready-made effect shader that applies CSS colour filters to a node and its subtree…
set(*, uniforms: dict[str, float \| tuple[float, ...]]) -> None Replaces the uniforms all at once; a mistake raises and changes nothing.

Events: none.

ShaderError

A shader's source or names are wrong, positioned in the WGSL you gave.

Inherits: ValueError → Exception → BaseException → object

Properties:

Property Type Description
line int \| None The 1-based line in your WGSL, or None when the problem has no position.
column int \| None The 1-based column in that line, or None.
source_line str \| None The text of that line, or None.

Events: none.

UnsupportedPlatform

Raised where a feature needs a platform this process is not on (a LayerWindow without a layer shell).

Inherits: RuntimeError → Exception → BaseException → object · Details: UnsupportedPlatform reference

Events: none.

Module functions and constants

Name Description
supports(feature: str, refresh: bool=False) -> bool Whether this process can use an optional feature.
register_font(data: bytes) -> list[str] Registers a font the caller already loaded.
set_system_fonts(enabled: bool) -> None Lets text use the fonts installed on this machine: for the glyphs the bundled and registered fonts lack (CJK, Hebrew, Indic…
system_fonts() -> bool Whether system fonts are on (set_system_fonts).
scheme_colors(scheme: Literal['light', 'dark']) -> dict[str, tuple[int, int, int, int]] The baseline colour roles of scheme, {role: (r, g, b, a)}: the 49 roles of the Material 3 baseline (seed #6750A4, standard…
write_png(path, rgba, width, height) -> None Saves Window.snapshot() pixels as a PNG file (0.5.4).
png_bytes(rgba, width, height) -> bytes The PNG file's bytes for straight-alpha RGBA8 pixels, for a framework that stores or sends them (0.5.4).
MONOSPACE_FONT_FAMILY The bundled monospace family a terminal always shapes with.
Color A type alias: an (r, g, b, a) tuple of ints, 0–255, straight alpha.