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

Usage#
import toga
widget = toga.NumberInput(min_value=1, max_value=10, step=0.001)
widget.value = 2.718
NumberInput’s properties can accept integers, floats, and strings containing
numbers, but they always return decimal.Decimal
objects to ensure
precision is retained.
Reference#
- class toga.widgets.numberinput.NumberInput(id=None, style=None, step=1, min_value=None, max_value=None, value=None, readonly=False, on_change=None)#
Create a new number input widget.
Inherits from
Widget
.- Parameters:
id – The ID for the widget.
style – A style object. If no style is provided, a default style will be applied to the widget.
step (Decimal) – The amount that any increment/decrement operations will apply to the widget’s current value.
min_value (Decimal | None) – If provided,
value
will be guaranteed to be greater than or equal to this minimum.max_value (Decimal | None) – If provided,
value
will be guaranteed to be less than or equal to this maximum.value (Decimal | None) – The initial value for the widget.
readonly (bool) – Can the value of the widget be modified by the user?
on_change (callable | None) – A handler that will be invoked when the the value of the widget changes.
- property max_value: Decimal | None#
The maximum bound for the widget’s value.
Returns
None
if there is no maximum bound.If the current
value
exceeds a newly specifiedmax_value
,value
will be clipped to conform to the new maximum.
- property min_value: Decimal | None#
The minimum bound for the widget’s value.
Returns
None
if there is no minimum bound.If the current
value
is less than a newly specifiedmin_value
,value
will be clipped to conform to the new minimum.
- property on_change: callable#
The handler to invoke when the value of the widget changes.
- property readonly: bool#
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.
- property step: Decimal#
The amount that any increment/decrement operations will apply to the widget’s current value. (Not all backends provide increment and decrement buttons.)
- property value: Decimal | None#
Current value of the widget, rounded to the same number of decimal places as
step
.Returns
None
if no value has been set on the widget.While the widget is being edited by the user, it is possible for the UI to contain text that isn’t a valid value according to the min/max range. In this case, the widget will return a value that has been clipped to the min/max range.