Skip to content

Confirm

Asks a yes/no question. danger=True paints the confirm button red; confirm_label and cancel_label rename the buttons.

ui.confirm · Category: Dialogs · Full reference →

ConfirmConfirm
  • Before destructive or irreversible actions: delete, overwrite, discard.
from pyzed import ui
ui.dialog_layer(main_view(), ui.confirm(
"Delete notes.py? This can't be undone.", on_delete, on_cancel,
title="Delete file", danger=True, confirm_label="Delete", width=360,
))
Confirm: NormalConfirm: Normal
Normal
Code
ui.confirm("Close all tabs?", on_confirm, on_cancel, title="Close tabs", width=320)
Confirm: danger=TrueConfirm: danger=True
danger=True
Code
ui.confirm("Delete notes.py?", on_delete, on_cancel, title="Delete file", danger=True,
confirm_label="Delete", width=320)
Confirm: kind="warning"Confirm: kind="warning"
kind="warning"
Code
ui.confirm("Overwrite the existing file?", on_confirm, on_cancel, kind="warning", width=320)
Confirm: confirm_label=, cancel_label=Confirm: confirm_label=, cancel_label=
confirm_label=, cancel_label=
Code
ui.confirm("Push 3 commits to main?", on_push, on_cancel, confirm_label="Push",
cancel_label="Not now", width=320)

Confirm has 2 events 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_confirm () The confirm button.
on_cancel () Cancel, 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 Files(pz.App):
def __init__(self):
self.files = ["notes.py", "todo.txt"]
self.deleting = "notes.py" # the file waiting for an answer
def delete(self): # on_confirm
self.files.remove(self.deleting)
self.deleting = None
def view(self):
dialog = None
if self.deleting:
dialog = ui.confirm(f"Delete {self.deleting}?", self.delete,
lambda: setattr(self, "deleting", None), # on_cancel
title="Delete file", danger=True, confirm_label="Delete")
return ui.dialog_layer(main_view(), dialog)
confirm(
message,
on_confirm,
on_cancel,
*,
title=None,
confirm_label=None,
cancel_label=None,
danger=False,
kind=None,
width=420,
theme=None,
)

Asks a yes/no question.

Property Default Description
message required Text or widget.
title None Title.
confirm_label None Confirm button text.
cancel_label None Cancel button text.
danger False Paints the confirm button red and labels it Delete.
kind None Adds an icon, as in alert.
width 420 Width: pixels, "fill", "shrink" or "fill:N" (proportion).
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_confirm, on_cancel (events).

Full reference →