Skip to content

TimePickerEntryMode 继承自: Enum

TimePicker 对话框的交互式输入模式。

在 DIAL(表盘)模式下,会显示一个时钟表盘,用户点击或拖动来选取时间。在 INPUT(输入)模式下,会显示 TextField,用户直接键入想要选择的时间。

示例 ​

python
from datetime import time

import flet as ft


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

    picker = ft.TimePicker(value=time(hour=19, minute=30))

    def open_picker(entry_mode: ft.TimePickerEntryMode):
        picker.entry_mode = entry_mode
        page.show_dialog(picker)

    def showcase_card(entry_mode: ft.TimePickerEntryMode) -> 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 TimePicker",
                        icon=ft.Icons.SCHEDULE,
                        on_click=lambda _, m=entry_mode: open_picker(m),
                    ),
                ],
            ),
        )

    page.appbar = ft.AppBar(title="TimePickerEntryMode Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text("Open the picker to compare dial/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.TimePickerEntryMode],
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
DIAL—'dial'User picks time from a clock dial. Can switch to INPUT by activating a mode button in the time picker dialog.
INPUT—'input'User can input the time by typing it into text fields. Can switch to DIAL by activating a mode button in the time picker dialog.
DIAL_ONLY—'dialOnly'User can only pick time from a clock dial. There is no user interface to switch to another mode.
INPUT_ONLY—'inputOnly'User can only input the time by typing it into text fields. There is no user interface to switch to another mode.

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