NumberInput¶
A text input that is limited to numeric input.





Not supported
Not supported
Usage¶
import toga
widget = toga.NumberInput(min=1, max=10, step=0.001)
widget.value = 2.718
NumberInput's properties can accept Decimal, int, float, or str containing numbers, but they always return Decimal objects to ensure precision is retained.
Reference¶
toga.NumberInput ¶
NumberInput(
id=None,
style=None,
step=1,
min=None,
max=None,
value=None,
readonly=False,
on_change=None,
**kwargs,
)
Bases: Widget
Create a new number input widget.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The ID for the widget.
TYPE:
|
style
|
A style object. If no style is provided, a default style will be applied to the widget.
TYPE:
|
step
|
The amount that any increment/decrement operations will apply to the widget's current value.
TYPE:
|
min
|
If provided,
TYPE:
|
max
|
If provided,
TYPE:
|
value
|
The initial value for the widget.
TYPE:
|
readonly
|
Can the value of the widget be modified by the user?
TYPE:
|
on_change
|
A handler that will be invoked when the value of the widget changes.
TYPE:
|
kwargs
|
Initial style properties.
DEFAULT:
|
max
property
writable
¶
max
min
property
writable
¶
min
readonly
property
writable
¶
readonly
Can the value of the widget be modified by the user?
This only controls manual changes by the user (i.e., typing at the
keyboard). Programmatic changes are permitted while the widget has
readonly enabled.
step
property
writable
¶
step
The amount that any increment/decrement operations will apply to the widget's current value. (Not all backends provide increment and decrement buttons.)
value
property
writable
¶
value
Current value of the widget, rounded to the same number of decimal
places as step, or None if no value has been set.
If this property is set to a value outside of the min/max range, it will be clipped.
While the widget is being edited by the user, it is possible for the UI to contain a value which is outside of the min/max range, or has too many decimal places. In this case, this property will return a value that has been clipped and rounded, and the visible text will be updated to match as soon as the widget loses focus.
toga.widgets.numberinput.OnChangeHandler ¶
Bases: Protocol
__call__ ¶
__call__(widget, **kwargs)
A handler to invoke when the value is changed.
| PARAMETER | DESCRIPTION |
|---|---|
widget
|
The NumberInput that was changed.
TYPE:
|
kwargs
|
Ensures compatibility with arguments added in future versions.
TYPE:
|