App#
The application window — the root of every bootstack program. App behaves
as an implicit vertical stack: widgets created inside its with block are
placed top-to-bottom in its content area. Build the window, then call run()
to show it and start the event loop.
Usage#
Building the window#
Open an App as a context manager, add content inside the block, and call
run() afterwards. run() shows the window and blocks until it closes.
import bootstack as bs
with bs.App(title="Notes", size=(800, 600), padding=16, gap=8) as app:
bs.Label("Hello!", font="heading-lg")
bs.Button("Quit", on_click=app.close)
app.run()
close() ends the program from code — the natural action for a Quit command
or menu item. It always closes (it does not run the on_close veto handlers
below).
Window controls#
The window’s show-state is controlled with these methods. They work the same on
App, AppShell, and Window.
Method |
Effect |
|---|---|
|
Close the window and end |
|
Hide the window without destroying it, and bring it back. |
|
Minimize to the taskbar/dock, or maximize where supported. |
|
Enter or leave fullscreen. |
|
Keep the window above all others, or release it. |
app.set_fullscreen(True) # kiosk / presentation mode
app.minimize()
app.hide() # later: app.show()
Closing and cleanup#
Two hooks fire around the window going away, and they are distinct:
on_closeguards the window’s close button. It runs before the window closes and can veto it — returnFalseto keep the window open, orNone/Trueto allow it.on_destroyfires once when the window (or any widget) is actually torn down — the place for cleanup. It cannot be canceled. See Events.
with bs.App(title="Editor") as app:
def confirm_quit():
if document.modified and not bs.confirm("Discard unsaved changes?"):
return False # veto — the window stays open
app.on_close(confirm_quit)
app.run()
The handler can also be passed at construction with on_close=. The
programmatic close() does not run these handlers — it always closes.
Window options#
Size and placement are constructor options:
bs.App(
title="Notes",
size=(800, 600),
min_size=(480, 360),
resizable=(True, True),
)
Theme, locale, and configuration#
An App is configured through flat constructor keyword arguments
(theme, locale, …), and the same options are read and changed at runtime
through matching app.* properties — assigning app.theme or app.locale
takes effect live.
with bs.App(title="Notes", theme="bootstrap-dark", locale="de_DE") as app:
bs.Button("Toggle theme", on_click=bs.toggle_theme)
app.run()
See App Configuration for the full configuration reference — every
option, the locale-derived read-only properties, persisting state across
launches with a Store, and App.from_store().
See also#
AppShell — an App with a built-in command bar, sidebar
navigation, and page stack: the standard desktop-app scaffold.
Window — a secondary window opened from a running app.
API#
The complete reference for App lives on the
Application API page. At a glance:
The application window. |
Full Example#
1
2with bs.App(title="Bootstack", size=(560, 400), padding=24, gap=14) as app:
3 with app.menubar.add_menu("File") as file:
4 file.add_action("New", shortcut="Mod+N", on_click=lambda: bs.toast("New"))
5 file.add_separator()
6 file.add_action("Quit", shortcut="Mod+Q", on_click=app.close)
7
8 bs.Label("Welcome to bootstack", font="heading-lg")
9 bs.Label(
10 "Build native desktop apps in pure Python.",
11 font="body",
12 accent="secondary",
13 )
14 bs.TextField(label="Project name", value="my-app")
15 with bs.HStack(gap=8):
16 bs.Button("Create", accent="primary")
17 bs.Button("Cancel", variant="outline", on_click=app.close)
18app.run()