Dialog layer
Shows a dialog centered over base with a dimmed backdrop; clicking the backdrop calls on_dismiss. With dialog=None it returns base unchanged, so keep which dialog is open in your state and always wrap the view with it.
ui.dialog_layer · Category: Dialogs · Full reference →


ui.dialog_layer( main_view(), ui.confirm("Delete notes.py? This can't be undone.", on_delete, on_cancel, title="Delete file", danger=True, width=340), on_dismiss=on_cancel,)When to use
Section titled “When to use”- Around your whole view, to show any of the dialogs on this page or a
ui.modal.
import pyzed as pzfrom pyzed import ui
class Files(pz.App): def __init__(self): self.asking = False
def close(self): self.asking = False
def view(self): dialog = None if self.asking: dialog = ui.confirm("Delete main.py?", self.delete, self.close, title="Delete file", danger=True) return ui.dialog_layer(self.main_view(), dialog, on_dismiss=self.close)Variants
Section titled “Variants”Dialog
Section titled “Dialog”

ui.alertCode
ui.dialog_layer(main_view(), ui.alert("Export finished.", on_close, kind="success", width=280))

ui.modalCode
ui.dialog_layer(main_view(), ui.modal(ui.muted("Any content."), title="Modal", on_close=on_close, width=280), on_dismiss=on_close)

dialog=NoneCode
ui.dialog_layer(main_view(), None)Events
Section titled “Events”Dialog layer 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_dismiss |
() |
Sent when the backdrop is clicked. |
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 Files(pz.App): def __init__(self): self.asking = True
def close(self): self.asking = False
def view(self): dialog = ui.confirm("Delete main.py?", self.close, self.close, danger=True) if self.asking else None return ui.dialog_layer(main_view(), dialog, on_dismiss=self.close) # click on the backdropclass Files(pz.App): asking = True
def update(self, message): if message in ("delete", "cancel"): self.asking = False
def view(self): dialog = ui.confirm("Delete main.py?", "delete", "cancel", danger=True) if self.asking else None return ui.dialog_layer(main_view(), dialog, on_dismiss="cancel")from dataclasses import dataclass
@dataclass(frozen=True)class State: asking: bool = True
def view(state, set_state): close = lambda: set_state(asking=False) dialog = ui.confirm("Delete main.py?", close, close, danger=True) if state.asking else None return ui.dialog_layer(main_view(), dialog, on_dismiss=close)Properties and API
Section titled “Properties and API”ui.dialog_layer
Section titled “ui.dialog_layer”dialog_layer(base, dialog=None, *, on_dismiss=None, theme=None)Shows a dialog centered over base with a dimmed backdrop. With dialog=None it returns base unchanged, so it can always wrap the view. See Dialogs.
| Property | Default | Description |
|---|---|---|
base |
required | The UI underneath. |
dialog |
None |
A dialog from the functions below, or ui.modal. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_dismiss (events).