mo.ui.button
Create an interactive button that triggers actions when clicked.
Signature
mo.ui.button(
value: object = None,
*,
label: str = "click here",
on_click: Callable[[object], object] | None = None,
on_change: Callable[[object], None] | None = None,
kind: Literal["neutral", "success", "warn", "danger"] = "neutral",
disabled: bool = False,
tooltip: str | None = None,
full_width: bool = False,
keyboard_shortcut: str | None = None
)
Parameters
Initial value associated with the button
label
str
default:"'click here'"
Text displayed on the button
on_click
Callable[[object], object]
Callback function called when button is clicked. Return value becomes the button’s new value.
Callback function called when button value changes
kind
'neutral' | 'success' | 'warn' | 'danger'
default:"'neutral'"
Visual style of the button
Whether the button is disabled
Tooltip text shown on hover
Whether button takes full width of container
Keyboard shortcut to trigger the button (e.g., “Ctrl+Enter”)
Example
import marimo as mo
# Simple button
button = mo.ui.button(label="Click me")
button
# Button with callback
count = mo.state(0)
def increment(value):
count.set(count() + 1)
return count()
button = mo.ui.button(
value=0,
label=f"Clicked {count()} times",
on_click=increment
)
# Styled buttons
mo.hstack([
mo.ui.button(label="Neutral", kind="neutral"),
mo.ui.button(label="Success", kind="success"),
mo.ui.button(label="Warning", kind="warn"),
mo.ui.button(label="Danger", kind="danger"),
])
Use on_click when you want to update the button’s value based on clicks. Use on_change for side effects.