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

Selectbox and Multiselect

Selectbox

A dropdown for choosing one value.

with sc.Selectbox(
    'Choose a branch',
    options=('main', 'dev', 'release'),
    value='main',
) as box:
    @box.value.on_change
    def _():
        branch.set(box.value.get())
ArgumentTypeMeaning
labelstr | PropertyLabel
optionssequence | PropertyChoices
indexintSelected position
valueanySelected value
formatcallable or sequenceLabels
placeholderstr | PropertyHint while nothing is picked
accept_new_optionboolOffer an input row in the dropdown
format_new_optioncallableConvert typed text into a value
take_new_optioncallableHandle typed text yourself
truncate_startboolShow the tail of an overlong label
enabledbool | PropertyWhether input is accepted
label_visibilitystrSee Inputs

Properties: label, options, index, value, placeholder.

Signals: value.on_change, options.on_change.

Accepting a new option

sc.Selectbox(
    'Channel',
    options=('A', 'B'),
    accept_new_option=True,
)

A submitted value that is not already an option is added at the front and selected. format_new_option converts the text before it is stored:

sc.Selectbox(
    'Port',
    options=(80, 443),
    accept_new_option=True,
    format_new_option=lambda x: int(x, 0),
)

take_new_option replaces that behavior entirely. Nothing is added to options; the callable receives the text and decides what to do. This is what a path bar uses.

Width

With width='content', the trigger is as wide as the widest option, not as wide as the current value. Switching options therefore does not make the control jump in size.

Multiselect

A dropdown for choosing several values.

with sc.Multiselect(
    'Select chart results',
    options=('Droop', 'PSD', 'SNDR'),
    value=('Droop', 'PSD'),
) as box:
    @box.value.on_change
    def _():
        print(box.value.get())
ArgumentTypeMeaning
labelstr | PropertyLabel
optionssequence | PropertyChoices
valuesequence | PropertySelected values
formatcallable or sequenceLabels
placeholderstr | PropertyHint while nothing is selected
height'fixed' | size keywordDefault 'fixed'
label_visibilitystrSee Inputs

Properties: label, options, value, placeholder.

Signals: value.on_change.

Selection order

The selection keeps the order in which rows were ticked. That order is what the trigger shows, what value reports, and what the server stores. Ticking adds to the end; unticking removes from the list.

Height

height='fixed' keeps the trigger on one line and scrolls the summary sideways. This avoids the control growing taller as more options are picked. Pass a size keyword to override it.