Prompt
Asks for a line of text: a controlled input plus Cancel and OK. Enter or the button calls on_submit.
ui.prompt · Category: Dialogs · Full reference →


ui.dialog_layer(main_view(), ui.prompt( "Rename", "notes.py", on_input, on_submit, on_cancel, message="New name for the file:", width=360,))When to use
Section titled “When to use”- For quick names: rename a file, name a new branch, save a view.
import pyzed as pzfrom pyzed import ui
class Files(pz.App): def __init__(self): self.new_name = None
def view(self): dialog = None if self.new_name is not None: dialog = ui.prompt("Rename", self.new_name, lambda t: setattr(self, "new_name", t), self.rename, lambda: setattr(self, "new_name", None)) return ui.dialog_layer(self.main_view(), dialog)Variants
Section titled “Variants”Content
Section titled “Content”

Code
ui.prompt("New branch", "", on_input, on_submit, on_cancel, placeholder="feature/…", width=340)

message=Code
ui.prompt("Rename", "notes.py", on_input, on_submit, on_cancel, message="New name for the file:", width=340)

submit_label=Code
ui.prompt("Save view", "My view", on_input, on_submit, on_cancel, submit_label="Save", width=340)Events
Section titled “Events”Prompt has 3 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_input |
(text) |
Receives each edit. |
on_submit |
() |
Enter or the submit 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().
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.name = "notes.py" self.new_name = "notes.py" # None while the dialog is closed
def rename(self): # on_submit: Enter or the button self.name, self.new_name = self.new_name, None
def view(self): dialog = None if self.new_name is not None: dialog = ui.prompt("Rename", self.new_name, lambda text: setattr(self, "new_name", text), # on_input self.rename, lambda: setattr(self, "new_name", None), # on_cancel message="New name for the file:") return ui.dialog_layer(main_view(), dialog)from dataclasses import dataclass
@dataclassclass Typed: text: str
class Files(pz.App): name, new_name = "notes.py", "notes.py"
def update(self, message): match message: case Typed(text): self.new_name = text case "rename": self.name, self.new_name = self.new_name, None case "cancel": self.new_name = None
def view(self): dialog = ui.prompt("Rename", self.new_name, Typed, "rename", "cancel") \ if self.new_name is not None else None return ui.dialog_layer(main_view(), dialog)from dataclasses import dataclass
@dataclass(frozen=True)class State: name: str = "notes.py" draft: str = "notes.py" renaming: bool = True
def view(state, set_state): if not state.renaming: return ui.label(state.name) return ui.dialog_layer(main_view(), ui.prompt( "Rename", state.draft, lambda text: set_state(draft=text), lambda: set_state(name=state.draft, renaming=False), lambda: set_state(renaming=False)))Properties and API
Section titled “Properties and API”ui.prompt
Section titled “ui.prompt”prompt( title, value, on_input, on_submit, on_cancel, *, message=None, placeholder='', submit_label=None, cancel_label=None, id=None, width=440, theme=None,)Asks for a line of text.
| Property | Default | Description |
|---|---|---|
title |
required | Title. |
value |
required | Current text. |
message |
None |
Text above the field. |
placeholder |
"" |
Hint text shown when empty. |
submit_label |
None |
Submit button text. |
cancel_label |
None |
Cancel button text. |
id |
None |
Field id (for Command.focus). |
width |
440 |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_input, on_submit, on_cancel (events).