Skip to main content

TextBox

A Fluent text box.

Example:

fluent.TextBox(placeholder="Email", keyboard_type=ft.KeyboardType.EMAIL)
fluent.TextBox(placeholder="Password", password=True)
TextBox
TextBox

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 when multiline is True.
  • min_lines - The minimum number of lines to occupy when multiline is True.
  • multiline - Whether the text can span several lines.
  • password - Whether to hide the entered text, for example for passwords.
  • placeholder - The hint shown while value is 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

  • on_blur - Called when this text box loses focus.
  • on_change - Called when the text changes.
  • on_focus - Called when this text box receives focus.
  • on_submit - Called when the user submits the text, for example by pressing Enter.

Methods

  • focus - Requests focus for this text box.

Example​

Fluent TextBox​

Sourceplay_arrowTry Online
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)
text_box
Typing a name

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this text box should be focused on initial display.

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.

keyboard_typeclass-attributeinstance-attribute​

keyboard_type: KeyboardType = KeyboardType.TEXT

The type of on-screen keyboard to show.

max_lengthclass-attributeinstance-attribute​

max_length: int | None = None

The maximum number of characters that can be entered.

max_linesclass-attributeinstance-attribute​

max_lines: int | None = None

The 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 = None

The minimum number of lines to occupy when multiline is True.

multilineclass-attributeinstance-attribute​

multiline: bool = False

Whether 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 = False

Whether to hide the entered text, for example for passwords.

placeholderclass-attributeinstance-attribute​

placeholder: str | None = None

The hint shown while value is empty.

prefixclass-attributeinstance-attribute​

prefix: IconDataOrControl | None = None

An icon or control shown before the text.

read_onlyclass-attributeinstance-attribute​

read_only: bool = False

Whether the text can be selected but not changed.

suffixclass-attributeinstance-attribute​

suffix: IconDataOrControl | None = None

An icon or control shown after the text.

text_alignclass-attributeinstance-attribute​

text_align: TextAlign = TextAlign.START

How the text is aligned horizontally.

valueclass-attributeinstance-attribute​

value: str = ''

The current text of this text box.

Events​

on_blurclass-attributeinstance-attribute​

on_blur: ControlEventHandler[TextBox] | None = None

Called when this text box loses focus.

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[TextBox] | None = None

Called 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 = None

Called when this text box receives focus.

on_submitclass-attributeinstance-attribute​

on_submit: ControlEventHandler[TextBox] | None = None

Called when the user submits the text, for example by pressing Enter.

Methods​

focusasync​

focus()

Requests focus for this text box.