Skip to content

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 →

PromptPrompt
  • For quick names: rename a file, name a new branch, save a view.
import pyzed as pz
from 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)
Prompt: Title onlyPrompt: Title only
Title only
Code
ui.prompt("New branch", "", on_input, on_submit, on_cancel, placeholder="feature/…", width=340)
Prompt: message=Prompt: message=
message=
Code
ui.prompt("Rename", "notes.py", on_input, on_submit, on_cancel, message="New name for the file:",
width=340)
Prompt: submit_label=Prompt: submit_label=
submit_label=
Code
ui.prompt("Save view", "My view", on_input, on_submit, on_cancel, submit_label="Save", width=340)

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

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

Full reference →