TextBox
A Fluent text box.
Example:
fluent.TextBox(placeholder="Email", keyboard_type=ft.KeyboardType.EMAIL)
fluent.TextBox(placeholder="Password", password=True)

Inherits: LayoutControl
Properties
autofocus- Whether this text box should be focused on initial display.error_text- An error message shown in red below the box, which also gets a red underline.keyboard_type- The type of on-screen keyboard to show.max_length- The maximum number of characters that can be entered.max_lines- The maximum number of lines to show whenmultilineisTrue.min_lines- The minimum number of lines to occupy whenmultilineisTrue.multiline- Whether the text can span several lines.password- Whether to hide the entered text, for example for passwords.placeholder- The hint shown whilevalueis empty.prefix- An icon or control shown before the text.read_only- Whether the text can be selected but not changed.suffix- An icon or control shown after the text.text_align- How the text is aligned horizontally.value- The current text of this text box.
Events
Methods
focus- Requests focus for this text box.
Example
Fluent TextBox
import flet_fluent_ui as fluent
import flet as ft
def main(page: ft.Page):
page.title = "Fluent TextBox"
def handle_change(e: ft.Event[fluent.TextBox]):
greeting.value = f"Hello, {e.control.value}!" if e.control.value else ""
greeting = ft.Text()
page.add(
ft.SafeArea(
content=ft.Column(
width=300,
controls=[
fluent.TextBox(
key="name",
placeholder="Your name",
prefix=fluent.FluentIcons.PERSON,
on_change=handle_change,
),
fluent.TextBox(placeholder="Password", password=True),
fluent.TextBox(placeholder="Notes", multiline=True, min_lines=3),
greeting,
],
)
)
)
if __name__ == "__main__":
ft.run(main)

Properties
autofocusclass-attributeinstance-attribute
autofocus: bool = FalseWhether this text box should be focused on initial display.
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.
keyboard_typeclass-attributeinstance-attribute
keyboard_type: KeyboardType = KeyboardType.TEXTThe type of on-screen keyboard to show.
max_lengthclass-attributeinstance-attribute
max_length: int | None = NoneThe maximum number of characters that can be entered.
max_linesclass-attributeinstance-attribute
max_lines: int | None = NoneThe maximum number of lines to show when multiline is True.
If None, the text box grows with its text without a limit.
min_linesclass-attributeinstance-attribute
min_lines: int | None = NoneThe minimum number of lines to occupy when multiline is True.
multilineclass-attributeinstance-attribute
multiline: bool = FalseWhether the text can span several lines.
A multiline text box grows with its text, from min_lines up to
max_lines, and Enter inserts a new line.
passwordclass-attributeinstance-attribute
password: bool = FalseWhether to hide the entered text, for example for passwords.
placeholderclass-attributeinstance-attribute
placeholder: str | None = NoneThe hint shown while value is empty.
prefixclass-attributeinstance-attribute
prefix: IconDataOrControl | None = NoneAn icon or control shown before the text.
read_onlyclass-attributeinstance-attribute
read_only: bool = FalseWhether the text can be selected but not changed.
suffixclass-attributeinstance-attribute
suffix: IconDataOrControl | None = NoneAn icon or control shown after the text.
text_alignclass-attributeinstance-attribute
text_align: TextAlign = TextAlign.STARTHow the text is aligned horizontally.
Events
on_blurclass-attributeinstance-attribute
on_blur: ControlEventHandler[TextBox] | None = NoneCalled when this text box loses focus.
on_changeclass-attributeinstance-attribute
on_change: ControlEventHandler[TextBox] | None = NoneCalled when the text changes.
The data property of the event handler argument
contains the new text.
on_focusclass-attributeinstance-attribute
on_focus: ControlEventHandler[TextBox] | None = NoneCalled when this text box receives focus.
on_submitclass-attributeinstance-attribute
on_submit: ControlEventHandler[TextBox] | None = NoneCalled when the user submits the text, for example by pressing Enter.