Skip to content

number

A kind of input that handles numbers.

Properties

Name Type Default Description
value(★) Any
dynamic

The numerical value represented by this control.

label str None

The label associated with the number field.
This provides context to the user and improves accessibility.

step Union[int, float]
dynamic
1

The increment or decrement applied to the value when the user clicks the arrow buttons.

step_multiplier Union[int, float]
dynamic
10

The factor by which the step value is multiplied when the user holds the Shift key while clicking the arrow buttons.

min Union[int, float]
dynamic

The minimum acceptable value.
Values below this threshold are invalid.

max Union[int, float]
dynamic

The maximum acceptable value.
Values above this threshold are invalid.

action_on_blur bool False

If True, the on_action callback is triggered when the number control looses keyboard focus (e.g., when the user presses the Tab key). When this happens, the key name for the event (set in the args property of the payload parameter to the callback function) is set to "Tab".

change_delay int App config

The minimum interval (in milliseconds) between two consecutive calls to the on_change callback.
The default value is defined at the application configuration level by the change_delay configuration option.
if None, the delay is set to 300 ms.
If set to -1, the callback is triggered only when the user presses the Enter key.

on_action Union[str, Callable]

A function or the name of a function that is triggered when a specific key is pressed.
The callback function is invoked with the following parameters:

  • state (State): the state instance.
  • id (str): the identifier of the control if it has one.
  • payload (dict): the callback details
    This dictionary has the following keys:
    • action: the name of the action that triggered this callback.
    • args (list):
      • The key name pressed.
      • The variable name.
      • The current value of the variable.

action_keys str "Enter"

A semicolon-separated list of keys that can trigger the on_action callback.
Authorized values are Enter, Escape, and function keys F1 to F12.

width Union[str, int] None

The width of the element, in CSS units.

on_change Union[str, Callable]

A function or the name of a function that is triggered when the value changes.
The callback function receives the following parameters:

  • state (State): the state instance.
  • var_name (str): the bound variable name.
  • value (Any): the updated value.

propagate bool App config

Determines whether the control's value is automatically reflected in the bound application variable.
The default value is defined at the application configuration level by the propagate configuration option.
If True, any change to the control's value is immediately reflected in the variable.

active bool
dynamic
True

Indicates if this element is active.
If False, the element is disabled, and user interaction is not allowed.

id str

The identifier assigned to the rendered HTML component.
This can be used in callbacks or to target the element for styling.

properties dict[str, Any]

A dictionary of additional properties that can be set to the element.

class_name str
dynamic

A space-separated list of CSS class names to be applied to the generated HTML element.
These classes are added to the default taipy-number class.

hover_text str
dynamic

The text that is displayed when the user hovers over the element.

(★)value is the default property for this visual element.

Usage

Simple

The number control provides a dedicated field for entering numerical values. It includes up and down arrows, allowing users to adjust the value easily without needing to type.

Let’s say you have a numerical variable that you want users to modify:

value = 50

You can bind this variable to a number control with the following definition: definition:

Definition

<|{value}|number|>
<taipy:number>{value}</taipy:number>
import taipy.gui.builder as tgb
...
tgb.number("{value}")

Below is an example of how the control would appear on the page:

A 'number' control

Specifying boundaries

You can restrict the range of valid inputs by setting the min and max properties for the number control.

Using the same variable from the previous example, here’s how you can define a number control that limits the values between 10 and 60:

Definition

<|{value}|number|min=10|max=60|>
<taipy:number min="10" max="60">{value}</taipy:number>
import taipy.gui.builder as tgb
...
tgb.number("{value}", min=10, max=60)

While the visual appearance of the control remains the same, users will only be able to input values within the specified range.

Setting the increment step

You can define how much the value changes when the up or down arrows are pressed by setting the step property.

Using the same variable from the previous example, here’s how you can define a number control where the value increases or decreases by 2:

Definition

<|{value}|number|step=2|>
<taipy:number step="2">{value}</taipy:number>
import taipy.gui.builder as tgb
...
tgb.number("{value}", step=2)

Although the appearance of the control remains unchanged, pressing the up or down arrow will now increment or decrement the value by 2.

Styling

All the number controls are generated with the "taipy-number" CSS class. You can use this class name to select the number controls on your page and apply style.

Stylekit support

The Stylekit provides a specific class that you can use to style number controls:

  • fullwidth
    If a number control uses the fullwidth class, then it uses the whole available horizontal space.