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)

Inherits: LayoutControl
Properties
allow_expressions- Whether the user can type a math expression, such as2 + 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 thePage Up/Page Downkeys 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 theUp/Downkeys 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
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)

Properties
allow_expressionsclass-attributeinstance-attribute
allow_expressions: bool = FalseWhether the user can type a math expression, such as 2 + 3 * 4, which is
replaced with its result.
autofocusclass-attributeinstance-attribute
autofocus: bool = FalseWhether this number box should be focused on initial display.
clear_buttonclass-attributeinstance-attribute
clear_button: bool = TrueWhether a button to clear the box is shown while it has focus and text.
error_textclass-attributeinstance-attribute
error_text: str | None = NoneAn 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 = 10How much the Page Up/Page Down keys change the value.
maxclass-attributeinstance-attribute
max: Number | None = NoneThe largest allowed value.
If None, there is no upper limit.
minclass-attributeinstance-attribute
min: Number | None = NoneThe smallest allowed value.
If None, there is no lower limit.
placeholderclass-attributeinstance-attribute
placeholder: str | None = NoneThe hint shown while the box is empty.
precisionclass-attributeinstance-attribute
precision: int | None = NoneThe 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 = NoneAn icon or control shown before the number.
small_changeclass-attributeinstance-attribute
small_change: Number = 1How much the spin buttons and the Up/Down keys change the value.
spin_buttonsclass-attributeinstance-attribute
spin_buttons: bool = TrueWhether the up and down buttons are shown at the end of the box.
Events
on_changeclass-attributeinstance-attribute
on_change: ControlEventHandler[NumberBox] | None = NoneCalled when value changes.
The data property of the event handler argument
contains the new value, or None when the box was cleared.