Skip to content

DatePickerEntryMode 继承自: Enum

Mode of date entry method for the date picker dialog.

示例 ​

python
import datetime

import flet as ft


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    today = datetime.datetime.now()
    picker = ft.DatePicker(
        first_date=datetime.datetime(year=today.year - 1, month=1, day=1),
        last_date=datetime.datetime(year=today.year + 1, month=12, day=31),
    )

    def open_picker(entry_mode: ft.DatePickerEntryMode):
        picker.entry_mode = entry_mode
        picker.date_picker_mode = ft.DatePickerMode.DAY
        page.show_dialog(picker)

    def showcase_card(entry_mode: ft.DatePickerEntryMode) -> ft.Container:
        return ft.Container(
            width=320,
            padding=12,
            border=ft.Border.all(1, ft.Colors.RED),
            border_radius=10,
            bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
            content=ft.Column(
                spacing=8,
                controls=[
                    ft.Text(entry_mode.name, weight=ft.FontWeight.BOLD),
                    ft.Button(
                        "Open DatePicker",
                        icon=ft.Icons.CALENDAR_MONTH,
                        on_click=lambda _, m=entry_mode: open_picker(m),
                    ),
                ],
            ),
        )

    page.appbar = ft.AppBar(title="DatePickerEntryMode Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Open the picker to compare calendar and input entry modes."
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[showcase_card(m) for m in ft.DatePickerEntryMode],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
CALENDAR—'calendar'User picks a date from calendar grid. Can switch to INPUT by activating a mode button in the dialog.
INPUT—'input'User can input the date by typing it into a text field. Can switch to CALENDAR by activating a mode button in the dialog.
CALENDAR_ONLY—'calendarOnly'User can only pick a date from calendar grid. There is no user interface to switch to another mode.
INPUT_ONLY—'inputOnly'User can only input the date by typing it into a text field. There is no user interface to switch to another mode.

关注我,学习大模型、大数据、Python等热门技术。