Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Button

Button-style widgets trigger actions. They have no value of their own, except for ToggleButton.

Button

with sc.Button('Save', type='primary') as button:
    @button.on_click
    def _():
        save()
ArgumentTypeMeaning
labelstr | PropertyButton text
type'secondary' | 'primary'Visual style, default 'secondary'
helpstr | PropertyMarkdown tooltip
widthsize keywordDefault 'content'
enabledbool | PropertyDefault True
on_clickcallableOptional handler, attached at construction

Properties: text, type, enabled, help.

Signals: on_click.

type, enabled, and help are reactive, so a button can change appearance or availability as state changes:

sc.Button(
    'Deploy',
    enabled=sc.bind(state.ready, lambda x: x),
)

IconButton

A button that contains only an icon. A bare material icon name is wrapped as :material/<name>: automatically.

sc.IconButton('refresh', help='Reload the list')
ArgumentTypeMeaning
iconstr | PropertyIcon name or short label
helpstrTooltip; recommended

Other arguments are inherited from Button.

A button that opens a menu of options. Choosing a row sets value and closes the menu, without a server round trip.

menu = sc.MenuButton('Export', options=('CSV', 'JSON'))

@menu.value.on_change
def _():
    export_as(menu.value.get())
ArgumentTypeMeaning
labelstr | PropertyTrigger label
optionssequence | PropertyMenu rows
valueanyCurrent choice
formatcallable or sequenceRow labels
panel_max_heightintScroll the menu past this height

Properties: text, options, value.

ToggleButton

A canary extra: a button that stays lit while its value is true.

with sc.ToggleButton('Bold') as bold:
    @bold.value.on_change
    def _():
        apply_style(bold.value.get())
ArgumentTypeMeaning
labelstr | PropertyButton text
valuebool | PropertyInitial on / off state
help, width, enabledas Button
on_clickcallableRuns after value flips

Properties: value, and a read-only type derived from value ('primary' while on, 'secondary' while off).

ToggleButton does not accept a type argument. Writing type raises an error, so the look cannot disagree with the state.