Skip to content

Button

Bases: Static

A simple clickable button.

ACTIVE_EFFECT_DURATION = 0.3 class-attribute

When buttons are clicked they get the -active class for this duration (in seconds)

__init__(label=None, disabled=False, variant='default', *, name=None, id=None, classes=None)

Create a Button widget.

Parameters:

Name Type Description Default
label str

The text that appears within the button.

None
disabled bool

Whether the button is disabled or not.

False
variant ButtonVariant

The variant of the button.

'default'
name str | None

The name of the button.

None
id str | None

The ID of the button in the DOM.

None
classes str | None

The CSS classes of the button.

None

error(label=None, disabled=False, *, name=None, id=None, classes=None) classmethod

Utility constructor for creating an error Button variant.

Parameters:

Name Type Description Default
label str

The text that appears within the button.

None
disabled bool

Whether the button is disabled or not.

False
name str | None

The name of the button.

None
id str | None

The ID of the button in the DOM.

None
classes str | None

The CSS classes of the button.

None

Returns:

Name Type Description
Button Button

A Button widget of the 'error' variant.

press()

Respond to a button press.

success(label=None, disabled=False, *, name=None, id=None, classes=None) classmethod

Utility constructor for creating a success Button variant.

Parameters:

Name Type Description Default
label str

The text that appears within the button.

None
disabled bool

Whether the button is disabled or not.

False
name str | None

The name of the button.

None
id str | None

The ID of the button in the DOM.

None
classes(str | None

The CSS classes of the button.

required

Returns:

Name Type Description
Button Button

A Button widget of the 'success' variant.

validate_label(label)

Parse markup for self.label

warning(label=None, disabled=False, *, name=None, id=None, classes=None) classmethod

Utility constructor for creating a warning Button variant.

Parameters:

Name Type Description Default
label str

The text that appears within the button.

None
disabled bool

Whether the button is disabled or not.

False
name str | None

The name of the button.

None
id str | None

The ID of the button in the DOM.

None
classes str | None

The CSS classes of the button.

None

Returns:

Name Type Description
Button Button

A Button widget of the 'warning' variant.

watch_mouse_over(value)

Update from CSS if mouse over state changes.