Skip to main content

NumberBox

A Fluent number box: a text box for numbers, with buttons to step the value up and down.

The value is checked when the user presses Enter, clicks outside the box or uses the buttons: text that is not a number is reverted, and values out of min..max are clamped.

Example:

fluent.NumberBox(value=3, min=0, max=10)
fluent.NumberBox(value=2.5, small_change=0.5, precision=1)
NumberBox
NumberBox

Inherits: LayoutControl

Properties

  • allow_expressions - Whether the user can type a math expression, such as 2 + 3 * 4, which is replaced with its result.
  • autofocus - Whether this number box should be focused on initial display.
  • clear_button - Whether a button to clear the box is shown while it has focus and text.
  • error_text - An error message shown in red below the box, which also gets a red underline.
  • large_change - How much the Page Up/Page Down keys change the value.
  • max - The largest allowed value.
  • min - The smallest allowed value.
  • placeholder - The hint shown while the box is empty.
  • precision - The maximum number of decimal places shown.
  • prefix - An icon or control shown before the number.
  • small_change - How much the spin buttons and the Up/Down keys change the value.
  • spin_buttons - Whether the up and down buttons are shown at the end of the box.
  • value - The current number.

Events

Example​

Fluent NumberBox​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft

PRICE = 4.5


def main(page: ft.Page):
page.title = "Fluent NumberBox"

def handle_change(e: ft.Event[fluent.NumberBox]):
quantity = e.control.value or 0
total.value = f"Total: ${quantity * PRICE:.2f}"

total = ft.Text(f"Total: ${PRICE:.2f}")

page.add(
ft.SafeArea(
content=ft.Column(
width=220,
controls=[
ft.Text("Coffee beans, $4.50 per bag"),
fluent.NumberBox(
key="quantity",
value=1,
min=1,
max=20,
precision=0,
on_change=handle_change,
),
total,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
number_box
Typing a quantity

Properties​

allow_expressionsclass-attributeinstance-attribute​

allow_expressions: bool = False

Whether the user can type a math expression, such as 2 + 3 * 4, which is replaced with its result.

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this number box should be focused on initial display.

clear_buttonclass-attributeinstance-attribute​

clear_button: bool = True

Whether a button to clear the box is shown while it has focus and text.

error_textclass-attributeinstance-attribute​

error_text: str | None = None

An error message shown in red below the box, which also gets a red underline.

Set it to tell the user that the value is not valid, and set it to None to hide it.

large_changeclass-attributeinstance-attribute​

large_change: Number = 10

How much the Page Up/Page Down keys change the value.

maxclass-attributeinstance-attribute​

max: Number | None = None

The largest allowed value.

If None, there is no upper limit.

minclass-attributeinstance-attribute​

min: Number | None = None

The smallest allowed value.

If None, there is no lower limit.

placeholderclass-attributeinstance-attribute​

placeholder: str | None = None

The hint shown while the box is empty.

precisionclass-attributeinstance-attribute​

precision: int | None = None

The maximum number of decimal places shown. Trailing zeros are not shown.

If None, up to 2 decimal places are shown. It can't be changed after the number box is first shown.

prefixclass-attributeinstance-attribute​

prefix: IconDataOrControl | None = None

An icon or control shown before the number.

small_changeclass-attributeinstance-attribute​

small_change: Number = 1

How much the spin buttons and the Up/Down keys change the value.

spin_buttonsclass-attributeinstance-attribute​

spin_buttons: bool = True

Whether the up and down buttons are shown at the end of the box.

valueclass-attributeinstance-attribute​

value: Number | None = None

The current number.

If None, the box is empty.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[NumberBox] | None = None

Called when value changes.

The data property of the event handler argument contains the new value, or None when the box was cleared.