MODULE v1.8.0

ui

pykraken.ui

A declarative UI and layout submodule.

Reference

PYTHON API

button

function
button(text: str, style: ui.Style = <ui.Style object>) -> bool

Create a clickable text button.

The button is evaluated against the previous frame's bounds and returns True when it is clicked during the current frame.

Args

  • text (str) — The label displayed on the button.
  • style (Style, optional) — Visual and layout settings for the button.

Returns

  • bool — True if the button was clicked this frame, otherwise False.

column

function
column(style: ui.Style | None = None, gap: float = 0.0, padding: float = 0.0, align: ui.Align = Align.START, justify: ui.Align = Align.START) -> ui._Context

Create a vertical container.

Children are laid out top to bottom unless alignment or spacing overrides are applied on the returned context.

Args

  • style (Style, optional) — Base style for the container.
  • gap (float, optional) — Space between child elements. Defaults to 0.0.
  • padding (float, optional) — Inner padding of the container. Defaults to 0.0.
  • align (Align, optional) — Cross-axis alignment for children. Defaults to Start.
  • justify (Align, optional) — Main-axis justification for children. Defaults to Start.

Returns

  • _Context — A context manager for the column.

label

function
label(text: str, style: ui.Style = <ui.Style object>) -> None

Create a non-interactive text label.

Args

  • text (str) — The text to display.
  • style (Style, optional) — Visual and layout settings for the label.

panel

function
panel(style: ui.Style = <ui.Style object>) -> None

Create a non-interactive container element.

Panels draw their background, texture, and borders using the provided style.

root

function
root(bounds: Rect, direction: ui.Direction = Direction.VERTICAL, align: ui.Align = Align.START, justify: ui.Align = Align.START) -> ui._RootContext

Create a root UI context for the current frame.

The root defines the available bounds for the UI tree and controls the default layout direction and alignment. Use it as a context manager.

Args

  • bounds (Rect) — The available region for the UI.
  • direction (Direction, optional) — The root layout direction. Defaults to Vertical.
  • align (Align, optional) — Cross-axis alignment for root children. Defaults to Start.
  • justify (Align, optional) — Main-axis justification for root children. Defaults to Start.

Returns

  • _RootContext — A context manager that finalizes the UI when exited.

row

function
row(style: ui.Style | None = None, gap: float = 0.0, padding: float = 0.0, align: ui.Align = Align.START, justify: ui.Align = Align.START) -> ui._Context

Create a horizontal container.

Children are laid out left to right unless the active direction or alignment settings are changed on the returned context.

Args

  • style (Style, optional) — Base style for the container.
  • gap (float, optional) — Space between child elements. Defaults to 0.0.
  • padding (float, optional) — Inner padding of the container. Defaults to 0.0.
  • align (Align, optional) — Cross-axis alignment for children. Defaults to Start.
  • justify (Align, optional) — Main-axis justification for children. Defaults to Start.

Returns

  • _Context — A context manager for the row.

stack

function
stack(style: ui.Style | None = None, padding: float = 0.0, align: ui.Align = Align.START, justify: ui.Align = Align.START) -> ui._Context

Create an overlapping container.

Stack children share the same container space instead of being arranged in a linear flow.

Args

  • style (Style, optional) — Base style for the container.
  • padding (float, optional) — Inner padding of the container. Defaults to 0.0.
  • align (Align, optional) — Alignment for children inside the stack. Defaults to Start.
  • justify (Align, optional) — Justification for children inside the stack. Defaults to Start.

Returns

  • _Context — A context manager for the stack.

Find your next step

Start typing to search the manual.