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

NumberInput

A box for entering a number.

with sc.NumberInput('Workers', value=4, min_value=1, step=1) as box:
    @box.value.on_change
    def _():
        workers.set(box.value.get())
ArgumentTypeMeaning
labelstr | PropertyLabel
valueint | float | PropertyCurrent number
min_valueint | floatInclusive lower bound
max_valueint | floatInclusive upper bound
stepint | floatStepper increment, default 0
formatcallableDisplay formatter (for example hex)
placeholderstr | PropertyHint while empty
label_visibilitystrSee Inputs

Properties: label, value, placeholder.

Signals: value.on_change, on_submit, on_editing_finished.

Integer versus float

The initial value decides the widget’s numeric type:

sc.NumberInput('Count', value=0)     # int widget
sc.NumberInput('Ratio', value=0.0)   # float widget

An int widget requires int bounds and an int step. A float widget also accepts ints and converts them to float.

The client sends the text; the server parses it with the widget’s type. An int widget therefore accepts both '41' and '0x29'.

Stepper

step=0 (the default) shows no stepper. A positive value adds + / - controls. If the stepper does not fit the available width, it degrades to a vertical form and is eventually dropped.

Signals

  • on_value: the committed value changed.
  • on_submit: Enter was pressed; carries the raw text.
  • on_editing_finished: editing ended (submit or blur); carries the raw text.

A submit emits both on_submit and on_editing_finished, in that order.

Validation

Constructing a widget with an out-of-range value raises ValueError. Passing a bound property that later falls out of range leaves the validation to your handler.