Disclosure
A header with an arrow that shows or hides content. You own the open state: change it in on_toggle.
ui.disclosure · Category: Lists and menus · Full reference →


pz.column([ ui.disclosure("Advanced options", ui.muted("Shown while the section is open."), open=True, on_toggle=on_toggle), ui.disclosure("Environment variables", ui.muted("Hidden"), open=False, on_toggle=on_toggle, end=ui.badge("3")),], spacing=10, width=380)When to use
Section titled “When to use”- To hide advanced options or details until they are needed.
import pyzed as pzfrom pyzed import ui
class Form(pz.App): def __init__(self): self.advanced = False
def view(self): return ui.disclosure("Advanced options", self.advanced_options(), open=self.advanced, on_toggle=lambda: setattr(self, "advanced", not self.advanced))Variants
Section titled “Variants”

open=FalseCode
pz.container(ui.disclosure("Advanced options", ui.muted("…"), open=False, on_toggle=on_toggle), width=300)

open=TrueCode
pz.container(ui.disclosure("Advanced options", ui.muted("Shown while open."), open=True, on_toggle=on_toggle), width=300)

end=Code
pz.container(ui.disclosure("Environment", ui.muted("…"), open=False, on_toggle=on_toggle, end=ui.badge("3")), width=300)Events
Section titled “Events”Disclosure 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_toggle |
() |
Message or callable when the header 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 Form(pz.App): def __init__(self): self.advanced = False
def view(self): return ui.disclosure("Advanced options", ui.muted("Proxy, timeouts…"), open=self.advanced, on_toggle=lambda: setattr(self, "advanced", not self.advanced)) # no argumentclass Form(pz.App): advanced = False
def update(self, message): if message == "toggle advanced": self.advanced = not self.advanced
def view(self): return ui.disclosure("Advanced options", ui.muted("…"), open=self.advanced, on_toggle="toggle advanced")from dataclasses import dataclass
@dataclass(frozen=True)class State: advanced: bool = False
def view(state, set_state): return ui.disclosure("Advanced options", ui.muted("…"), open=state.advanced, on_toggle=lambda: set_state(advanced=not state.advanced))Properties and API
Section titled “Properties and API”ui.disclosure
Section titled “ui.disclosure”disclosure(title, content, *, open, on_toggle=None, end=None, theme=None)A collapsible section: a header with an arrow that shows or hides content. You own the open state: change it in on_toggle.
| Property | Default | Description |
|---|---|---|
title |
required | Title (text or widget). |
content |
required | Content. |
open |
required | Whether it is open. |
end |
None |
Widgets at the end (right). |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_toggle (events).