Hello World

Every libui-python application follows the same pattern: create an App, build a widget tree, show the window, and wait.

A window with a button

"""Hello world — a window with a button and a reactive counter."""

import libui
from libui.declarative import App, Window, VBox, Label, Button, State


async def main():
    app = App()
    count = State(0)

    app.build(
        window=Window(
            "Hello",
            400,
            300,
            child=VBox(
                Label(text=count.map(lambda n: f"Count: {n}")),
                Button("Click me", on_clicked=lambda: count.update(lambda n: n + 1)),
            ),
        )
    )

    app.show()
    await app.wait()


libui.run(main())
Hello world window

Key points:

  • async def main() — your app runs as an async function

  • App() — manages the application lifecycle

  • State(0) — a reactive container; bound widgets auto-update

  • count.map(...) — derives a read-only computed value

  • count.update(...) — transforms the value and notifies subscribers

  • libui.run(main()) — starts the UI event loop and asyncio

The Window takes a title, width, height, and a single child widget. VBox stacks its children vertically.