Skip to content

Dropdown

Examples#

Live example

Color selection with filtering#

import flet as ft


def main(page: ft.Page):
    def get_options():
        colors = [
            ft.Colors.RED,
            ft.Colors.BLUE,
            ft.Colors.YELLOW,
            ft.Colors.PURPLE,
            ft.Colors.LIME,
        ]
        return [
            ft.DropdownOption(
                key=color.value,
                content=ft.Text(value=color.value, color=color),
            )
            for color in colors
        ]

    def handle_dropdown_change(e: ft.Event[ft.Dropdown]):
        e.control.color = e.control.value
        page.update()

    page.add(
        ft.Dropdown(
            editable=True,
            label="Color",
            options=get_options(),
            on_change=handle_dropdown_change,
        )
    )


ft.run(main)

color-selection-with-filtering

Icon selection#

import flet as ft


def main(page: ft.Page):
    def get_options():
        icons = [
            {"name": "Smile", "icon": ft.Icons.SENTIMENT_SATISFIED_OUTLINED},
            {"name": "Cloud", "icon": ft.Icons.CLOUD_OUTLINED},
            {"name": "Brush", "icon": ft.Icons.BRUSH_OUTLINED},
            {"name": "Heart", "icon": ft.Icons.FAVORITE},
        ]
        return [
            ft.DropdownOption(key=icon["name"], leading_icon=icon["icon"])
            for icon in icons
        ]

    page.add(
        ft.Dropdown(
            border=ft.InputBorder.UNDERLINE,
            enable_filter=True,
            editable=True,
            leading_icon=ft.Icons.SEARCH,
            label="Icon",
            options=get_options(),
        )
    )


ft.run(main)

icon-selection

Styled dropdowns#

import flet as ft


def main(page: ft.Page):
    page.add(
        # 1
        ft.Dropdown(
            text_size=20,
            content_padding=10,
            color=ft.Colors.PURPLE_200,
            bgcolor=ft.Colors.BLUE_200,
            filled=True,
            border_radius=30,
            border_color=ft.Colors.GREEN_800,
            focused_border_color=ft.Colors.GREEN_ACCENT_400,
            focused_border_width=5,
            options=[
                ft.DropdownOption("a", "Item A"),
                ft.DropdownOption("b", "Item B"),
                ft.DropdownOption("c", "Item C"),
            ],
        ),
        # 2
        ft.Dropdown(
            border_radius=30,
            filled=True,
            fill_color=ft.Colors.RED_400,
            border_color=ft.Colors.TRANSPARENT,
            bgcolor=ft.Colors.RED_200,
            color=ft.Colors.CYAN_400,
            focused_border_color=ft.Colors.PINK_300,
            focused_border_width=20,
            options=[
                ft.DropdownOption("a", "Item A"),
                ft.DropdownOption("b", "Item B"),
                ft.DropdownOption("c", "Item C"),
            ],
        ),
        # 3
        ft.Dropdown(
            border_color=ft.Colors.PINK_ACCENT,
            focused_border_color=ft.Colors.GREEN_ACCENT_400,
            focused_border_width=25,
            border_radius=30,
            width=150,
            border_width=5,
            options=[
                ft.DropdownOption("a", "Item A"),
                ft.DropdownOption("b", "Item B"),
                ft.DropdownOption("c", "Item C"),
            ],
        ),
        # 4
        ft.Container(
            padding=ft.Padding.only(bottom=20),
            content=ft.Dropdown(
                text_size=30,
                color=ft.Colors.ORANGE_ACCENT,
                border_radius=20,
                filled=True,
                border_width=0,
                autofocus=True,
                focused_border_color=ft.Colors.GREEN_100,
                focused_border_width=10,
                width=200,
                height=50,
                options=[
                    ft.dropdown.Option("a", "Item A"),
                    ft.dropdown.Option("b", "Item B"),
                    ft.dropdown.Option("c", "Item C"),
                ],
            ),
        ),
        # 5
        ft.Dropdown(
            text_size=30,
            border_radius=20,
            filled=True,
            border_width=0,
            focused_border_color=ft.Colors.GREEN_100,
            focused_border_width=10,
            content_padding=20,
            width=200,
            options=[
                ft.DropdownOption(
                    key="a",
                    text="Item A",
                    style=ft.ButtonStyle(
                        shape=ft.BeveledRectangleBorder(radius=15),
                        color={
                            ft.ControlState.HOVERED: ft.Colors.WHITE,
                            ft.ControlState.FOCUSED: ft.Colors.BLUE,
                            ft.ControlState.DEFAULT: ft.Colors.BLACK,
                        },
                    ),
                ),
                ft.DropdownOption(
                    key="b",
                    text="Item B",
                    style=ft.ButtonStyle(
                        shape=ft.BeveledRectangleBorder(radius=15),
                        color={
                            ft.ControlState.HOVERED: ft.Colors.WHITE,
                            ft.ControlState.FOCUSED: ft.Colors.BLUE,
                            ft.ControlState.DEFAULT: ft.Colors.BLACK,
                        },
                    ),
                ),
                ft.DropdownOption(
                    key="c",
                    text="Item C",
                    style=ft.ButtonStyle(
                        shape=ft.BeveledRectangleBorder(radius=15),
                        color={
                            ft.ControlState.HOVERED: ft.Colors.WHITE,
                            ft.ControlState.FOCUSED: ft.Colors.BLUE,
                            ft.ControlState.DEFAULT: ft.Colors.BLACK,
                        },
                    ),
                ),
            ],
        ),
    )


ft.run(main)

Dropdown #

Bases: ConstrainedControl

A dropdown control that allows users to select a single option from a list of options.

animate_offset #

animate_offset: AnimationValue | None = None

Enables implicit animation of the offset property.

More information here.

animate_opacity #

animate_opacity: AnimationValue | None = None

Enables implicit animation of the opacity property.

More information here.

animate_position #

animate_position: AnimationValue | None = None

Enables implicit animation of the positioning properties (left, right, top and bottom).

More information here.

animate_rotation #

animate_rotation: AnimationValue | None = None

Enables implicit animation of the rotate property.

More information here.

animate_scale #

animate_scale: AnimationValue | None = None

Enables implicit animation of the scale property.

More information here.

animate_size #

animate_size: AnimationValue | None = None

TBD

aspect_ratio #

aspect_ratio: Number | None = None

TBD

autofocus #

autofocus: bool = False

Whether the control will be selected as the initial focus. If there is more than one control on a page with autofocus set, then the first one added to the page will get focus.

badge #

badge: BadgeValue | None = None

A badge to show on top of this control.

bgcolor #

bgcolor: ControlStateValue[ColorValue] | None = None

The background color of the dropdown menu in various ControlState states.

border #

border: InputBorder | None = None

Border around input.

Defaults to InputBorder.OUTLINE.

border_color #

border_color: ColorValue | None = None

Border color. Could be transparent to hide the border.

border_radius #

border_radius: BorderRadiusValue | None = None

border_width #

border_width: Number = 1

The width of the border in virtual pixels. Set to 0 to completely remove border.

bottom #

bottom: Number | None = None

The distance that the child's bottom edge is inset from the bottom of the stack.

Note

Effective only if this control is a descendant of one of the following: Stack control, Page.overlay list.

capitalization #

capitalization: TextCapitalization | None = None

TBD

col #

col: ResponsiveNumber = 12

If a parent of this control is a ResponsiveRow, this property is used to determine how many virtual columns of a screen this control will span.

Can be a number or a dictionary configured to have a different value for specific breakpoints, for example col={"sm": 6}.

This control spans the 12 virtual columns by default.

Dimensions
Breakpoint Dimension
xs <576px
sm ≥576px
md ≥768px
lg ≥992px
xl ≥1200px
xxl ≥1400px

color #

color: ColorValue | None = None

Text color.

content_padding #

content_padding: PaddingValue | None = None

The padding for the input decoration's container.

data #

data: Any = skip_field()

Arbitrary data of any type.

dense #

dense: bool = False

Whether the TextField is part of a dense form (i.e., uses less vertical space).

disabled #

disabled: bool = False

Every control has disabled property which is False by default - control and all its children are enabled.

Note

The value of this property will be propagated down to all children controls recursively.

Example

For example, if you have a form with multiple entry controls you can disable them all together by disabling container:

ft.Column(
    disabled = True,
    controls=[
        ft.TextField(),
        ft.TextField()
    ]
)

editable #

editable: bool = False

TBD

elevation #

elevation: ControlStateValue[Number | None] | None = 8

The dropdown's menu elevation in various ControlState states.

enable_filter #

enable_filter: bool = False

Determine if the menu list can be filtered by the text input. Defaults to false.

If set to true, dropdown menu will show a filtered list. The filtered list will contain items that match the text provided by the input field, with a case-insensitive comparison.

enable_search: bool = True

Determine if the first item that matches the text input can be highlighted.

error_style #

error_style: TextStyle | None = None

The TextStyle to use for error_text.

error_text #

error_text: str | None = None

Text that appears below the input border.

If non-null, the border's color animates to red and the helper_text is not shown.

expand #

expand: bool | int | None = None

Specifies whether/how this control should expand to fill available space in its parent layout.

More information here.

Note

Has effect only if the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

expand_loose #

expand_loose: bool = False

Allows the control to expand along the main axis if space is available, but does not require it to fill all available space.

More information here.

Note

If expand_loose is True, it will have effect only if:

  • expand is not None and
  • the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

expanded_insets #

expanded_insets: PaddingValue | None = None

TBD

fill_color #

fill_color: ColorValue | None = None

Background color of the dropdown input text field.

Note

Will not be visible if filled=False.

filled #

filled: bool = False

Whether the decoration's container is filled with theme fill_color.

focused_border_color #

focused_border_color: ColorValue | None = None

Border color in focused state.

focused_border_width #

focused_border_width: Number | None = None

Border width in focused state.

height #

height: Number | None = None

Imposed Control height in virtual pixels.

helper_style #

helper_style: TextStyle | None = None

The TextStyle to use for helper_text.

helper_text #

helper_text: str | None = None

Text that provides context about the input's value, such as how the value will be used.

If non-null, the text is displayed below the input decorator, in the same location as error_text. If a non-null error_text value is specified then the helper text is not shown.

hint_style #

hint_style: TextStyle | None = None

The TextStyle to use for hint_text.

hint_text #

hint_text: str | None = None

Text that suggests what sort of input the field accepts.

Displayed on top of the input when it's empty and either (a) label is null or (b) the input has the focus.

hover_color #

hover_color: ColorValue | None = None

The color of the dropdown input text field when hovered.

input_filter #

input_filter: InputFilter | None = None

TBD

key #

key: (
    str | int | float | bool | ValueKey | ScrollKey | None
) = None

label #

label: StrOrControl | None = None

Optional text that describes the input field.

When the input field is empty and unfocused, the label is displayed on top of the input field (i.e., at the same location on the screen where text may be entered in the input field). When the input field receives focus (or if the field is non-empty) the label moves above, either vertically adjacent to, or to the center of the input field.

label_style #

label_style: TextStyle | None = None

The label's text style.

leading_icon #

leading_icon: IconValueOrControl | None = None

An optional Icon at the front of the text input field inside the decoration box.

If this is not null, the menu items will have extra paddings to be aligned with the text in the text field.

left #

left: Number | None = None

The distance that the child's left edge is inset from the left of the stack.

Note

Effective only if this control is a descendant of one of the following: Stack control, Page.overlay list.

menu_height #

menu_height: Number | None = None

The height of the dropdown menu.

If this is None, the menu will display as many items as possible on the screen.

menu_width #

menu_width: Number | None = None

The width of the dropdown menu.

If this is None, the menu width will be the same as input textfield width.

offset #

offset: OffsetValue | None = None

Applies a translation transformation before painting the control.

The translation is expressed as an Offset scaled to the control's size. So, Offset(x=0.25, y=0), for example, will result in a horizontal translation of one quarter the width of this control.

Example

The following example displays container at 0, 0 top left corner of a stack as transform applies -1 * 100, -1 * 100 (offset * control's size) horizontal and vertical translations to the control:

import flet as ft

def main(page: ft.Page):
    page.add(
        ft.Stack(
            width=1000,
            height=1000,
            controls=[
                ft.Container(
                    bgcolor="red",
                    width=100,
                    height=100,
                    left=100,
                    top=100,
                    offset=ft.Offset(-1, -1),
                )
            ],
        )
    )

ft.run(main)

on_animation_end #

on_animation_end: (
    ControlEventHandler[ConstrainedControl] | None
) = None

Called when animation completes.

Can be used to chain multiple animations.

The data property of the event handler argument contains the name of the animation.

More information here.

on_blur #

on_blur: ControlEventHandler[Dropdown] | None = None

Called when the control has lost focus.

on_change #

on_change: ControlEventHandler[Dropdown] | None = None

Called when the selected item of this dropdown has changed.

on_focus #

on_focus: ControlEventHandler[Dropdown] | None = None

Called when the control has received focus.

opacity #

opacity: Number = 1.0

Defines the transparency of the control.

Value ranges from 0.0 (completely transparent) to 1.0 (completely opaque without any transparency).

options #

options: list[DropdownOption] = field(default_factory=list)

A list of options to display in the dropdown.

page #

page: Page | PageView | None

The page (of type Page or PageView) to which this control belongs to.

parent #

parent: BaseControl | None

The direct ancestor(parent) of this control.

It defaults to None and will only have a value when this control is mounted (added to the page tree).

The Page control (which is the root of the tree) is an exception - it always has parent=None.

right #

right: Number | None = None

The distance that the child's right edge is inset from the right of the stack.

Note

Effective only if this control is a descendant of one of the following: Stack control, Page.overlay list.

rotate #

rotate: RotateValue | None = None

Transforms this control using a rotation around its center.

The value of rotate property could be one of the following types:

  • number - a rotation in clockwise radians. Full circle 360° is math.pi * 2 radians, 90° is pi / 2, 45° is pi / 4, etc.
  • Rotate - allows to specify rotation angle as well as alignment - the location of rotation center.
Example

For example:

ft.Image(
    src="https://picsum.photos/100/100",
    width=100,
    height=100,
    border_radius=5,
    rotate=Rotate(angle=0.25 * pi, alignment=ft.Alignment.CENTER_LEFT)
)

rtl #

rtl: bool = False

Whether the text direction of the control should be right-to-left (RTL).

scale #

scale: ScaleValue | None = None

Scales this control along the 2D plane. Default scale factor is 1.0, meaning no-scale.

Setting this property to 0.5, for example, makes this control twice smaller, while 2.0 makes it twice larger.

Different scale multipliers can be specified for x and y axis, by setting Control.scale property to an instance of Scale class. Either scale or scale_x and scale_y could be specified, but not all of them.

Example
ft.Image(
    src="https://picsum.photos/100/100",
    width=100,
    height=100,
    border_radius=5,
    scale=ft.Scale(scale_x=2, scale_y=0.5)
)

selected_suffix #

selected_suffix: Control | None = None

TBD

selected_trailing_icon #

selected_trailing_icon: IconValueOrControl = ARROW_DROP_UP

An optional icon at the end of the text field to indicate that the text field is pressed.

text_align #

text_align: TextAlign = START

The text align for the TextField of the Dropdown.

text_size #

text_size: Number | None = None

Text size in virtual pixels.

text_style #

text_style: TextStyle | None = None

The TextStyle to use for text in input text field.

tooltip #

tooltip: TooltipValue | None = None

The tooltip ot show when this control is hovered over.

top #

top: Number | None = None

The distance that the child's top edge is inset from the top of the stack.

Note

Effective only if this control is a descendant of one of the following: Stack control, Page.overlay list.

trailing_icon #

An icon to display at the end of the text field.

value #

value: str | None = None

key value of the selected option.

visible #

visible: bool = True

Every control has visible property which is True by default - control is rendered on the page. Setting visible to False completely prevents control (and all its children if any) from rendering on a page canvas. Hidden controls cannot be focused or selected with a keyboard or mouse and they do not emit any events.

width #

width: Number | None = None

Imposed Control width in virtual pixels.

before_event #

before_event(e: ControlEvent)

before_update #

before_update()

clean #

clean() -> None

did_mount #

did_mount()

focus #

focus()

focus_async #

focus_async()

init #

init()

is_isolated #

is_isolated()

update #

update() -> None

will_unmount #

will_unmount()