Skip to main content

EditableComboBox

A Fluent combo box that the user can also type into, to enter a value that is not one of the options.

The box fills the width it is given: give it a width in a row.

Example:

fluent.EditableComboBox(
width=200,
value="12",
items=[fluent.ComboBoxItem(value=str(size)) for size in [8, 10, 12, 14]],
)
EditableComboBox
EditableComboBox

Inherits: LayoutControl

Properties

  • autofocus - Whether this combo box should be focused on initial display.
  • error_text - An error message shown in red below the box.
  • items - The options to choose from.
  • value - The text in the box.

Events

  • on_blur - Called when the box loses focus.
  • on_change - Called when the user picks an option or enters other text.
  • on_focus - Called when the box receives focus.

Methods

  • focus - Requests focus for this combo box.

Example​

Fluent EditableComboBox​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


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

def change_font(e: ft.Event[fluent.EditableComboBox]):
sample.font_family = e.control.value

def change_size(e: ft.Event[fluent.EditableComboBox]):
size = int(e.control.value) if e.control.value.isdigit() else 0
if 1 <= size <= 72:
e.control.error_text = None
sample.size = size
else:
e.control.error_text = "Enter 1 to 72"

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Row(
vertical_alignment=ft.CrossAxisAlignment.START,
controls=[
fluent.EditableComboBox(
key="font",
width=160,
value="Arial",
items=[
fluent.ComboBoxItem(value=font)
for font in ["Arial", "Courier New", "Georgia"]
],
on_change=change_font,
),
fluent.EditableComboBox(
key="size",
width=120,
value="14",
items=[
fluent.ComboBoxItem(value=str(size))
for size in [10, 12, 14, 18, 24, 36]
],
on_change=change_size,
),
],
),
sample := ft.Text(
"The quick brown fox", font_family="Arial", size=14
),
]
)
)
)


if __name__ == "__main__":
ft.run(main)
editable_combo_box
Typing a size, typing one out of range, then picking one from the list

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this combo 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.

Set it to tell the user that the value is not valid, and set it to None to hide it. Unlike error_text, the box doesn't get a red underline.

itemsclass-attributeinstance-attribute​

items: list[ComboBoxItem] = field(default_factory=list)

The options to choose from.

Picking an option puts its value into the box, so the values should read well.

valueclass-attributeinstance-attribute​

value: str = ''

The text in the box.

It is updated when the user picks an option, presses Enter or leaves the box, not on every key press.

Events​

on_blurclass-attributeinstance-attribute​

on_blur: ControlEventHandler[EditableComboBox] | None = (
    None
)

Called when the box loses focus.

on_changeclass-attributeinstance-attribute​

on_change: (
    ControlEventHandler[EditableComboBox] | None
) = None

Called when the user picks an option or enters other text.

value holds the new text.

on_focusclass-attributeinstance-attribute​

on_focus: (
    ControlEventHandler[EditableComboBox] | None
) = None

Called when the box receives focus.

Methods​

focusasync​

focus()

Requests focus for this combo box.