Skip to main content

ComboBox

A Fluent combo box: a button that opens a list of options to pick one from.

Example:

fluent.ComboBox(
placeholder="Pick a color",
items=[
fluent.ComboBoxItem(value="red", text="Red"),
fluent.ComboBoxItem(value="green", text="Green"),
fluent.ComboBoxItem(value="blue", text="Blue"),
],
)
ComboBox
ComboBox

Inherits: LayoutControl

Properties

  • autofocus - Whether this combo box should be focused on initial display.
  • error_text - An error message shown in red below the combo box.
  • expand_to_fit - Whether the closed combo box fills the width it is given, instead of fitting its widest option.
  • items - The options to choose from.
  • placeholder - The hint shown while no option is chosen.
  • value - The value of the chosen option.

Events

  • on_change - Called when the chosen option changes.
  • on_close - Called when the list of options closes.
  • on_open - Called when the list of options opens.

Example​

Fluent ComboBox​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


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

def handle_change(e: ft.Event[fluent.ComboBox]):
status.value = f"Color: {e.control.value}"

status = ft.Text("No color chosen")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
fluent.ComboBox(
placeholder="Pick a color",
on_change=handle_change,
items=[
fluent.ComboBoxItem(value="red", text="Red"),
fluent.ComboBoxItem(value="green", text="Green"),
fluent.ComboBoxItem(value="blue", text="Blue"),
],
),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
combo_box
Choosing Green

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 combo box.

Set it to tell the user that the value is not valid, and set it to None to hide it.

expand_to_fitclass-attributeinstance-attribute​

expand_to_fit: bool = False

Whether the closed combo box fills the width it is given, instead of fitting its widest option.

itemsclass-attributeinstance-attribute​

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

The options to choose from.

placeholderclass-attributeinstance-attribute​

placeholder: StrOrControl | None = None

The hint shown while no option is chosen.

valueclass-attributeinstance-attribute​

value: str | None = None

The value of the chosen option.

If None, placeholder is shown.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[ComboBox] | None = None

Called when the chosen option changes.

The data property of the event handler argument contains the new value.

on_closeclass-attributeinstance-attribute​

on_close: ControlEventHandler[ComboBox] | None = None

Called when the list of options closes.

on_openclass-attributeinstance-attribute​

on_open: ControlEventHandler[ComboBox] | None = None

Called when the list of options opens.