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)

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: text 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

Public methods

Inherited from UIElement

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

Create a submittable form out of this UIElement.

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.