Skip to content

Alert

A message with a single OK button. kind ("info", "success", "warning", "error") adds an icon.

ui.alert · Category: Dialogs · Full reference →

AlertAlert
  • 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))
Alert: kind=NoneAlert: kind=None
kind=None
Code
ui.alert("The file was moved to the trash.", on_close, width=320)
Alert: kind="info"Alert: kind="info"
kind="info"
Code
ui.alert("A new version is available.", on_close, kind="info", width=320)
Alert: kind="success"Alert: kind="success"
kind="success"
Code
ui.alert("128 files were exported.", on_close, kind="success", title="Export", width=320)
Alert: kind="warning"Alert: kind="warning"
kind="warning"
Code
ui.alert("The disk is almost full.", on_close, kind="warning", width=320)
Alert: kind="error"Alert: kind="error"
kind="error"
Code
ui.alert("notes.py could not be opened.", on_close, kind="error", title="Error", width=320)
Alert: ok_label="Got it"Alert: ok_label="Got it"
ok_label="Got it"
Code
ui.alert("Shortcuts changed in this version.", on_close, ok_label="Got it", width=320)

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().

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)
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).

Full reference →