Skip to content

Split button

A button with a separate chevron on the right. on_press runs the main action and on_menu usually opens a ui.menu inside a ui.popover with the alternatives.

ui.split_button · Category: Actions · Full reference →

Split buttonSplit button
  • When one action is the usual one but there are a few variations (Run / Run with arguments).
  • Avoid it when the options are equally important: use a Select.
import pyzed as pz
from pyzed import ui
class Runner(pz.App):
def __init__(self):
self.menu_open = False
def view(self):
button = ui.split_button("Run", self.run, lambda: setattr(self, "menu_open", True), icon="play")
menu = ui.menu([ui.MenuItem("Run with arguments…", self.run_args),
ui.MenuItem("Debug", self.debug, icon="bug")]) if self.menu_open else None
return ui.popover(button, menu, y=32, on_dismiss=lambda: setattr(self, "menu_open", False))
Split button: variant="filled"Split button: variant="filled"
variant="filled"
Code
ui.split_button("Run", on_run, on_menu, icon="play")
Split button: variant="ghost"Split button: variant="ghost"
variant="ghost"
Code
ui.split_button("Run", on_run, on_menu, icon="play", variant="ghost")
Split button: variant="outline"Split button: variant="outline"
variant="outline"
Code
ui.split_button("Run", on_run, on_menu, icon="play", variant="outline")
Split button: variant="solid"Split button: variant="solid"
variant="solid"
Code
ui.split_button("Deploy", on_deploy, on_menu, icon="rocket", variant="solid")
Split button: size="sm"Split button: size="sm"
size="sm"
Code
ui.split_button("Build", on_build, on_menu, size="sm")
Split button: size="md"Split button: size="md"
size="md"
Code
ui.split_button("Build", on_build, on_menu, size="md")
Split button: size="lg"Split button: size="lg"
size="lg"
Code
ui.split_button("Build", on_build, on_menu, size="lg")
Split button: Text onlySplit button: Text only
Text only
Code
ui.split_button("Merge", on_merge, on_menu)
Split button: icon="git-merge"Split button: icon="git-merge"
icon="git-merge"
Code
ui.split_button("Merge", on_merge, on_menu, icon="git-merge")
Split button: tint="success"Split button: tint="success"
tint="success"
Code
ui.split_button("Deploy", on_press, on_menu, tint="success")
Split button: disabled=TrueSplit button: disabled=True
disabled=True
Code
ui.split_button("Run", on_press, on_menu, disabled=True)

Split button 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_press () Message or callable sent on press. None disables the control.
on_menu () Message or callable for the menu button.

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 Runner(pz.App):
def __init__(self):
self.menu_open = False
self.last = "nothing yet"
def run(self, how="run"):
self.last, self.menu_open = how, False
def view(self):
button = ui.split_button("Run", self.run, # on_press: the main action
lambda: setattr(self, "menu_open", True), # on_menu: the arrow
icon="play")
menu = ui.menu([ui.MenuItem("Debug", lambda: self.run("debug"), icon="bug")])
return pz.column([
ui.popover(button, menu if self.menu_open else None, y=32,
on_dismiss=lambda: setattr(self, "menu_open", False)),
ui.label(f"Last: {self.last}"),
], spacing=8)
split_button(
content,
on_press=None,
on_menu=None,
*,
icon=None,
variant='filled',
tint=None,
size='md',
disabled=False,
tooltip=None,
theme=None,
)

A button with a separate arrow for more options. on_press runs the main action and on_menu usually opens a ui.menu in a ui.popover.

Property Default Description
content required Button text.
icon None Name of a Lucide icon (pyzed icons lists them).
variant "filled" As in ui.button.
tint None As in ui.button.
size "md" "xs", "sm", "md" or "lg".
disabled False Disables both halves.
tooltip None Tooltip of the main half.
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_press, on_menu (events).

Full reference →