Skip to content

Slider

A slider provides a visual indication of adjustable content, as well as the current setting in the total range of content.

Use a slider when you want people to set defined values (such as volume or brightness), or when people would benefit from instant feedback on the effect of setting changes.

Slider

Default and disabled sliders

Inherits: LayoutControl, AdaptiveControl

Properties

Events

Examples#

Live example

Basic Example#

import flet as ft


def main(page: ft.Page):
    page.add(
        ft.Text("Default slider:"),
        ft.Slider(),
        ft.Text("Default disabled slider:"),
        ft.Slider(disabled=True),
    )


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

basic

Setting a custom label#


custom-label

Handling events#

import flet as ft


def main(page: ft.Page):
    def slider_changed(e: ft.Event[ft.Slider]):
        message.value = f"Slider changed to {e.control.value}"
        message.update()

    page.add(
        ft.Text("Slider with 'on_change' event:"),
        ft.Slider(
            key="slider",
            min=0,
            max=100,
            divisions=10,
            label="{value}%",
            on_change=slider_changed,
        ),
        message := ft.Text(),
    )


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

handling-events

Properties#

active_color class-attribute instance-attribute #

active_color: ColorValue | None = None

The color to use for the portion of the slider track that is active.

The "active" side of the slider is the side between the thumb and the minimum value.

autofocus class-attribute instance-attribute #

autofocus: bool = False

True if 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.

divisions class-attribute instance-attribute #

divisions: int | None = None

The number of discrete divisions.

Typically used with label to show the current discrete value.

If None, this slider is continuous.

inactive_color class-attribute instance-attribute #

inactive_color: ColorValue | None = None

The color for the inactive portion of the slider track.

The "inactive" side of the slider is the side between the thumb and the maximum value.

interaction class-attribute instance-attribute #

interaction: SliderInteraction | None = None

The allowed way for the user to interact with this slider.

If None, SliderTheme.interaction is used. If that's is also None, defaults to SliderInteraction.TAP_AND_SLIDE.

label class-attribute instance-attribute #

label: str | None = None

A label to show above the slider when the slider is active. The value of label may contain {value} which will be dynamically replaced with a current slider value. For example, "Volume: {value}".

It is used to display the value of a discrete slider, and it is displayed as part of the value indicator shape.

If not set, then the value indicator will not be displayed.

max class-attribute instance-attribute #

max: Number = 1.0

The maximum value the user can select.

Note
  • Must be greater than or equal to min.
  • If the min is equal to the max, then this slider is disabled.

Raises:

min class-attribute instance-attribute #

min: Number = 0.0

The minimum value the user can select.

Note
  • Must be less than or equal to max.
  • If the max is equal to the min, then this slider is disabled.

Raises:

mouse_cursor class-attribute instance-attribute #

mouse_cursor: MouseCursor | None = None

The cursor to be displayed when a mouse pointer enters or is hovering over this control.

overlay_color class-attribute instance-attribute #

overlay_color: ControlStateValue[ColorValue] | None = None

The highlight color that's typically used to indicate that the range slider thumb is in ControlState.HOVERED or ControlState.DRAGGED states.

padding class-attribute instance-attribute #

padding: PaddingValue | None = None

Determines the padding around this slider.

round class-attribute instance-attribute #

round: int = 0

The number of decimals displayed on the label containing value.

Defaults to 0, which displays value rounded to the nearest integer.

secondary_active_color class-attribute instance-attribute #

secondary_active_color: ColorValue | None = None

The color to use for the portion of the slider track between the thumb and the secondary_track_value.

secondary_track_value class-attribute instance-attribute #

secondary_track_value: Number | None = None

The secondary track value for this slider.

If not null, a secondary track using secondary_active_color is drawn between the thumb and this value, over the inactive track. If less than value, then the secondary track is not shown.

It can be ideal for media scenarios such as showing the buffering progress while the value shows the play progress.

thumb_color class-attribute instance-attribute #

thumb_color: ColorValue | None = None

The color of the thumb.

value class-attribute instance-attribute #

value: Number | None = None

The currently selected value for this slider.

The slider's thumb is drawn at a position that corresponds to this value.

Defaults to value of min.

Raises:

year_2023 class-attribute instance-attribute #

year_2023: bool | None = None

If this is set to False, this slider will use the latest Material Design 3 appearance, which was introduced in December 2023.

When True, the Slider will use the 2023 Material Design 3 appearance.

If not set, then the SliderTheme.year_2023 will be used, which is False by default.

If Theme.use_material3 is False, then this property is ignored.

Events#

on_blur class-attribute instance-attribute #

on_blur: ControlEventHandler[Slider] | None = None

Called when this slider has lost focus.

on_change class-attribute instance-attribute #

on_change: ControlEventHandler[Slider] | None = None

Called when the state of this slider is changed.

on_change_end class-attribute instance-attribute #

on_change_end: ControlEventHandler[Slider] | None = None

Called when the user is done selecting a new value for this slider.

on_change_start class-attribute instance-attribute #

on_change_start: ControlEventHandler[Slider] | None = None

Called when the user starts selecting a new value for this slider.

on_focus class-attribute instance-attribute #

on_focus: ControlEventHandler[Slider] | None = None

Called when this slider has received focus.