Alert
A message with a single OK button. kind ("info", "success", "warning", "error") adds an icon.
ui.alert · Category: Dialogs · Full reference →


ui.dialog_layer(main_view(), ui.alert("The export finished: 128 files were written.", on_close, title="Export", kind="success", width=360))When to use
Section titled “When to use”- To report something the user must acknowledge (an export finished, a file could not be opened).
from pyzed import ui
ui.dialog_layer(main_view(), ui.alert("The export finished: 128 files were written.", on_close, title="Export", kind="success", width=360))Variants
Section titled “Variants”

kind=NoneCode
ui.alert("The file was moved to the trash.", on_close, width=320)

kind="info"Code
ui.alert("A new version is available.", on_close, kind="info", width=320)

kind="success"Code
ui.alert("128 files were exported.", on_close, kind="success", title="Export", width=320)

kind="warning"Code
ui.alert("The disk is almost full.", on_close, kind="warning", width=320)

kind="error"Code
ui.alert("notes.py could not be opened.", on_close, kind="error", title="Error", width=320)Options
Section titled “Options”

ok_label="Got it"Code
ui.alert("Shortcuts changed in this version.", on_close, ok_label="Got it", width=320)Events
Section titled “Events”Alert has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Handler gets | When |
|---|---|---|
on_close |
() |
The button and the close icon. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Export(pz.App): def __init__(self): self.done = True
def view(self): alert = ui.alert("128 files were written.", lambda: setattr(self, "done", False), # on_close title="Export", kind="success") return ui.dialog_layer(main_view(), alert if self.done else None)class Export(pz.App): done = True
def update(self, message): if message == "ok": self.done = False
def view(self): return ui.dialog_layer(main_view(), ui.alert("128 files were written.", "ok", title="Export") if self.done else None)from dataclasses import dataclass
@dataclass(frozen=True)class State: done: bool = True
def view(state, set_state): alert = ui.alert("128 files were written.", lambda: set_state(done=False), title="Export") return ui.dialog_layer(main_view(), alert if state.done else None)Properties and API
Section titled “Properties and API”ui.alert
Section titled “ui.alert”alert(message, on_close, *, title=None, kind=None, ok_label=None, width=400, theme=None)A message with one button.
| Property | Default | Description |
|---|---|---|
message |
required | Text or widget. |
title |
None |
Title. |
kind |
None |
"info", "success", "warning" or "error" adds an icon. |
ok_label |
None |
Button text (default: OK, translated). |
width |
400 |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_close (events).