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())
Key points:
async def main()— your app runs as an async functionApp()— manages the application lifecycleState(0)— a reactive container; bound widgets auto-updatecount.map(...)— derives a read-only computed valuecount.update(...)— transforms the value and notifies subscriberslibui.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.