Button

class UI.Button

All attributes are read/write: You can access (read) and modify (set) any attribute at any time, and the changes will immediately reflect in the UI.

# setting up click handler
def click_handler():
    print('clicked')

# Creating basic button
card.create_ui_element(UI.Button, label="Click me!", onClick=click_handler)

# Setting attributes
button = card.create_ui_element(
    UI.Button,
    label="Click me!",
    variant="ghost",
    size="sm",
    color="danger",
    full_width=True,
    onClick=click_handler
)

##################################
# Example with asnychronus updates

button = card.create_ui_element(UI.Button, label="Submit")

async def click_handler():
    button.loading=True
    # Do some async tasks, for example fetch data from an API...
    button.loading=False
    # perform other updates

button.onClick = click_handler
Attribute
Value

label

any string

variant

"solid"

"bordered"

"ghost"

"light"

"flat"

"cta" Default: "solid"

color

"primary"

"default"

"success"

"danger"

Note: If cta variant is used, custom color will not be applied.

Default: "primary"

size

"sm"

"md" Default: "md"

full_width

True | False Default: False

disabled

True | False Default: False

loading

True | False Default: False

margin

See Margin. Default: "m-0"

visible

See Visible. Default: True

Events

Event
Arguments
Description

onClick

-

Triggered when the button is clicked.

Last updated

Was this helpful?