Button

Looking for a submit/run button?

If you’re looking for a button to trigger computation on click, consider using mo.ui.run_button.

class marimo.ui.button(on_click: Callable[[Any], Any] | None = None, value: Any | None = None, kind: Literal['neutral', 'success', 'warn', 'danger'] = 'neutral', disabled: bool = False, tooltip: str | None = None, *, label: str = 'click here', on_change: Callable[[Any], None] | None = None, full_width: bool = False, keyboard_shortcut: str | None = None)

A button with an optional callback and optional value.

Example.

# a button that when clicked will execute
# any cells referencing that button
button = mo.ui.button()
# a counter implementation
counter_button = mo.ui.button(
    value=0, on_click=lambda value: value + 1, label="increment"
)

# adding intent
delete_button = mo.ui.button(
    label="Do not click",
    kind="danger",
)

Attributes.

  • value: the value of the button

Initialization Args.

  • on_click: a callable called on click that takes the current value of the button and returns a new value

  • value: an initial value for the button

  • kind: ‘neutral’, ‘success’, ‘warn’, or ‘danger’

  • disabled: whether the button is disabled

  • label: markdown label for the element

  • on_change: optional callback to run when this element’s value changes

  • full_width: whether the input should take up the full width of its container

  • keyboard_shortcut: keyboard shortcut to trigger the button (e.g. ‘Ctrl-L’)

Public methods

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

send_message(message, buffers)

Send a message to the element rendered on the frontend from the backend.

Inherited from Html

batch(**elements)

Convert an HTML object with templated text into a UI element.

center()

Center an item.

right()

Right-justify.

left()

Left-justify.

callout([kind])

Create a callout containing this HTML element.

style([style])

Wrap an object in a styled container.

Public Data Attributes:

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.