TextField
A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard.
Example:
ft.TextField(label="Name", hint_text="Jane Doe")

Inherits: FormFieldControl, AdaptiveControl
Properties
always_call_on_tap- Whetheron_clickshould be called for every tap.animate_cursor_opacity- Whether the text cursor animates between transparent and opaque during each blink.autocorrect- Whether to enable autocorrection.autofill_hints- Helps the autofill service identify the type of this text input.autofocus- True if the control will be selected as the initial focus.can_request_focus- Whether this field can request focus.can_reveal_password- Displays a toggle icon button that allows revealing the entered password.capitalization- Enables automatic on-the-fly capitalization of entered text.clip_behavior- How the field's contents should be clipped.cursor_color- The color of TextField cursor.cursor_error_color- The color of the text cursor while the field is showing an error.cursor_height- Sets cursor height.cursor_radius- Sets cursor radius.cursor_width- Sets cursor width.enable_ime_personalized_learning- Whether the input method is allowed to learn from what the user types.enable_interactive_selection- Whether interactive text selection is enabled.enable_stylus_handwriting- Whether this field supports stylus handwriting input.enable_suggestions- Whether to show input suggestions as the user types.ignore_pointers- Whether this field ignores pointer events.ignore_up_down_keys- Whether to intercept Arrow-Up and Arrow-Down when this field has focus.input_filter- Provides as-you-type filtering/validation.keyboard_brightness- The brightness to use for the onscreen keyboard.keyboard_type- The type of keyboard to use for editing the text.max_length- Limits a maximum number of characters that can be entered into TextField.max_lines- The maximum number of lines to show at one time, wrapping if necessary.min_lines- The minimum number of lines to occupy when the content spans fewer lines.mouse_cursor- The mouse pointer to show while hovering over the field.multiline- Whether this field can contain multiple lines of text.obscuring_character- The single character used to mask the text whenpasswordisTrue.password- Whether to hide the text being edited.read_only- Whether the text can be changed.scroll_padding- Padding to keep around the field when a surrounding scrollable scrolls it into view.selection- Represents the current text selection or caret position in the field.selection_color- The color of TextField selection.shift_enter- Changes the behavior ofEnterbutton inmultilinetextfield to be chat-like, i.e.show_cursor- Whether the field's cursor is to be shown.smart_dashes_type- Whether to allow the platform to automatically format dashes.smart_quotes_type- Whether to allow the platform to automatically format quotes.strut_style- TheStrutStyleused for vertical text layout.text_align- How the text should be aligned horizontally.value- Current value of this text field.
Events
on_blur- Called when the control has lost focus.on_change- Called when the typed input for the TextField has changed.on_click- Called when the field is tapped.on_focus- Called when the control has received focus.on_paste_files- Called when the user pastes files into the field, such as a screenshot or an image copied from a web page or the OS file manager.on_selection_change- Called when the text selection or caret position changes.on_submit- Called when user presses ENTER while focus is on TextField.on_tap_outside- Called when a pointer-down event occurs outside the field while it is focused.
Examples
TextField
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
def handle_button_click(e: ft.Event[ft.Button]):
message.value = (
f"Textboxes values are: '{tb1.value}', '{tb2.value}', "
f"'{tb3.value}', '{tb4.value}', '{tb5.value}'."
)
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
tb1 := ft.TextField(label="Standard"),
tb2 := ft.TextField(
label="Disabled",
disabled=True,
value="First name",
),
tb3 := ft.TextField(
label="Read-only",
read_only=True,
value="Last name",
),
tb4 := ft.TextField(
label="With placeholder",
hint_text="Please enter text here",
),
tb5 := ft.TextField(
label="With an icon",
icon=ft.Icons.EMOJI_EMOTIONS,
),
ft.Button(content="Submit", on_click=handle_button_click),
message := ft.Text(),
],
),
),
)
if __name__ == "__main__":
ft.run(main)

Handling change events
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
def handle_field_change(e: ft.Event[ft.TextField]):
message.value = e.control.value
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.TextField(
key="handling_change_textfield",
label="Textbox with 'change' event:",
on_change=handle_field_change,
),
message := ft.Text(),
],
),
),
)
if __name__ == "__main__":
ft.run(main)

Handling selection changes
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
page.title = "Text selection"
def handle_selection_change(e: ft.TextSelectionChangeEvent[ft.TextField]):
selection.value = (
f"Selection: '{e.selected_text}'" if e.selected_text else "No selection."
)
selection_details.value = f"start={e.selection.start}, end={e.selection.end}"
caret.value = f"Caret position: {e.selection.end}"
async def select_characters(e: ft.Event[ft.Button]):
await field.focus()
field.selection = ft.TextSelection(
base_offset=0, extent_offset=len(field.value)
)
async def move_caret(e: ft.Event[ft.Button]):
await field.focus()
field.selection = ft.TextSelection(base_offset=0, extent_offset=0)
page.add(
ft.SafeArea(
content=ft.Column(
spacing=10,
controls=[
field := ft.TextField(
value=(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
),
multiline=True,
min_lines=3,
autofocus=True,
on_selection_change=handle_selection_change,
),
selection := ft.Text("Select some text from the field."),
selection_details := ft.Text(),
caret := ft.Text("Caret position: -"),
ft.Button(
content="Select all text",
on_click=select_characters,
),
ft.Button(
content="Move caret to start",
on_click=move_caret,
),
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Password with reveal button
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.TextField(
key="password_textfield",
label="Password with reveal button",
password=True,
can_reveal_password=True,
),
)
)
if __name__ == "__main__":
ft.run(main)

Multiline fields
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.TextField(
key="multiline_standard",
label="Standard",
multiline=True,
),
ft.TextField(
label="Disabled",
multiline=True,
disabled=True,
value="line1\nline2\nline3\nline4\nline5",
),
ft.TextField(
key="multiline_auto_height",
label="Auto adjusted height with max lines",
multiline=True,
min_lines=1,
max_lines=3,
),
],
),
),
)
if __name__ == "__main__":
ft.run(main)

Underlined and borderless TextFields
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.TextField(
key="underlined_field",
label="Underlined",
border=ft.UnderlineInputBorder(),
hint_text="Enter text here",
),
ft.TextField(
key="underlined_filled_field",
label="Underlined filled",
border=ft.UnderlineInputBorder(),
filled=True,
hint_text="Enter text here",
),
ft.TextField(
key="borderless_field",
label="Borderless",
border=ft.NoInputBorder(),
hint_text="Enter text here",
),
ft.TextField(
key="borderless_filled_field",
label="Borderless filled",
border=ft.NoInputBorder(),
filled=True,
hint_text="Enter text here",
),
],
),
),
)
if __name__ == "__main__":
ft.run(main)

Setting prefixes and suffixes
play_arrowTry Online
import flet as ft
def main(page: ft.Page):
def handle_button_click(e: ft.Event[ft.Button]):
message.value = (
"Textboxes values are: "
f"'{prefix_field.value}', "
f"'{suffix_field.value}', "
f"'{prefix_suffix_field.value}', "
f"'{color_field.value}'."
)
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
prefix_field := ft.TextField(
key="prefix_field",
label="With prefix",
prefix="https://",
),
suffix_field := ft.TextField(
key="suffix_field",
label="With suffix",
suffix=".com",
),
prefix_suffix_field := ft.TextField(
key="prefix_suffix_field",
label="With prefix and suffix",
prefix="https://",
suffix=".com",
enable_interactive_selection=True,
),
color_field := ft.TextField(
key="color_field",
label="My favorite color",
icon=ft.Icons.FORMAT_SIZE,
hint_text="Type your favorite color",
helper="You can type only one color",
counter="{value_length}/{max_length} chars used",
prefix_icon=ft.Icons.COLOR_LENS,
suffix="...is your color",
max_length=20,
),
ft.Button(
key="submit_button",
content="Submit",
on_click=handle_button_click,
),
message := ft.Text(),
],
),
),
)
if __name__ == "__main__":
ft.run(main)
