Skip to content

Button

Button

Bases: Static

A simple clickable button.

ACTIVE_EFFECT_DURATION class-attribute

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

Pressed

Bases: Message

Event sent when a Button is pressed.

Can be handled using on_button_pressed in a subclass of Button or in a parent widget in the DOM.

Attributes:

Name Type Description
button

The button that was pressed.

control: Button property

Alias for the button.

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

Create a Button widget.

Parameters:

Name Type Description Default
label TextType | None

The text that appears within the button.

None
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
disabled bool

Whether the button is disabled or not.

False

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

Utility constructor for creating an error Button variant.

Parameters:

Name Type Description Default
label TextType | None

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
disabled bool

Whether the button is disabled or not.

False

Returns:

Type Description
Button

A Button widget of the 'error' variant.

press()

Respond to a button press.

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

Utility constructor for creating a success Button variant.

Parameters:

Name Type Description Default
label TextType | None

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
disabled bool

Whether the button is disabled or not.

False

Returns:

Type Description
Button

A Button widget of the 'success' variant.

validate_label(label)

Parse markup for self.label

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

Utility constructor for creating a warning Button variant.

Parameters:

Name Type Description Default
label TextType | None

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
disabled bool

Whether the button is disabled or not.

False

Returns:

Type Description
Button

A Button widget of the 'warning' variant.

ButtonVariant module-attribute

The names of the valid button variants.

These are the variants that can be used with a Button.

InvalidButtonVariant

Bases: Exception

Exception raised if an invalid button variant is used.