Skip to content
Toga
0.5.3.dev143+gabcc6cdb6

NumberInput

A text input that is limited to numeric input.

/reference/images/numberinput-cocoa.png

/reference/images/numberinput-gtk.png

/reference/images/numberinput-winforms.png

/reference/images/numberinput-android.png

/reference/images/numberinput-iOS.png

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: str | None DEFAULT: None

style

A style object. If no style is provided, a default style will be applied to the widget.

TYPE: StyleT | None DEFAULT: None

step

The amount that any increment/decrement operations will apply to the widget's current value.

TYPE: NumberInputT DEFAULT: 1

min

If provided, value will be guaranteed to be greater than or equal to this minimum.

TYPE: NumberInputT | None DEFAULT: None

max

If provided, value will be guaranteed to be less than or equal to this maximum.

TYPE: NumberInputT | None DEFAULT: None

value

The initial value for the widget.

TYPE: NumberInputT | None DEFAULT: None

readonly

Can the value of the widget be modified by the user?

TYPE: bool DEFAULT: False

on_change

A handler that will be invoked when the value of the widget changes.

TYPE: OnChangeHandler | None DEFAULT: None

kwargs

Initial style properties.

DEFAULT: {}

max property writable

max

The maximum bound for the widget's value.

Returns None if there is no maximum bound.

When setting this property, the current value and min will be clipped against the new maximum value.

min property writable

min

The minimum bound for the widget's value.

Returns None if there is no minimum bound.

When setting this property, the current value and max will be clipped against the new minimum value.

on_change property writable

on_change

The handler to invoke when the value of the widget changes.

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: NumberInput

kwargs

Ensures compatibility with arguments added in future versions.

TYPE: Any DEFAULT: {}

toga.widgets.numberinput.NumberInputT module-attribute

NumberInputT