Skip to main content

DatePicker

A Fluent date picker: a field showing the month, day and year, which opens scrolling lists to pick each of them.

Example:

fluent.DatePicker(header="Birthday", value=date(1990, 4, 12))
DatePicker
DatePicker

Inherits: LayoutControl

Properties

  • autofocus - Whether this picker should be focused on initial display.
  • first_date - The earliest date that can be picked.
  • header - A label shown above the field.
  • last_date - The latest date that can be picked.
  • show_day - Whether the field shows the day.
  • show_month - Whether the field shows the month.
  • show_year - Whether the field shows the year.
  • value - The selected date.

Events

  • on_change - Called when the user picks a date and confirms it.

Example​

Fluent DatePicker​

Sourceplay_arrowTry Online
from datetime import date

import flet_fluent_ui as fluent

import flet as ft


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

def handle_change(e: ft.Event[fluent.DatePicker]):
# A picked date arrives in UTC: convert it to the local date.
day = e.control.value.astimezone()
status.value = f"Birthday: {day:%B} {day.day}, {day.year}"

status = ft.Text("Birthday: April 12, 1990")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
fluent.DatePicker(
key="birthday",
header="Birthday",
value=date(1990, 4, 12),
on_change=handle_change,
),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
date_picker
Picking a year

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this picker should be focused on initial display.

first_dateclass-attributeinstance-attribute​

first_date: DateTimeValue | None = None

The earliest date that can be picked.

If None, it is 100 years before today.

headerclass-attributeinstance-attribute​

header: str | None = None

A label shown above the field.

last_dateclass-attributeinstance-attribute​

last_date: DateTimeValue | None = None

The latest date that can be picked.

If None, it is 25 years after today.

show_dayclass-attributeinstance-attribute​

show_day: bool = True

Whether the field shows the day.

show_monthclass-attributeinstance-attribute​

show_month: bool = True

Whether the field shows the month.

show_yearclass-attributeinstance-attribute​

show_year: bool = True

Whether the field shows the year.

valueclass-attributeinstance-attribute​

value: DateTimeValue | None = None

The selected date.

If None, the field shows placeholders and the lists open at today's date.

After the user picks a date, it holds a datetime in UTC for midnight local time: use value.astimezone() to get the local date.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[DatePicker] | None = None

Called when the user picks a date and confirms it.

value holds the new date.