跳到主要内容

CupertinoTimerPicker

一个 iOS 风格的倒计时选择器。 要打开此控件,只需调用 page.open() 辅助方法。

import time
import flet as ft


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

timer_picker_value_ref = ft.Ref[ft.Text]()

def handle_timer_picker_change(e):
# e.data is the selected time in seconds
timer_picker_value_ref.current.value = time.strftime("%H:%M:%S", time.gmtime(int(e.data)))
page.update()

cupertino_timer_picker = ft.CupertinoTimerPicker(
value=3600,
second_interval=10,
minute_interval=1,
mode=ft.CupertinoTimerPickerMode.HOUR_MINUTE_SECONDS,
on_change=handle_timer_picker_change,
)

page.add(
ft.Row(
tight=True,
controls=[
ft.Text("TimerPicker Value:", size=23),
ft.CupertinoButton(
content=ft.Text(
ref=timer_picker_value_ref,
value="00:01:10",
size=23,
color=ft.cupertino_colors.DESTRUCTIVE_RED,
),
on_click=lambda e: page.open(
ft.CupertinoBottomSheet(
cupertino_timer_picker,
height=216,
padding=ft.padding.only(top=6),
)
),
),
],
),
)


ft.app(target=main)

属性

alignment

定义计时器选择器在其父元素内的定位方式。

对齐方式是 Alignment 类的一个实例。

默认为 alignment.center

bgcolor

计时器选择器的背景颜色

mode

计时器选择器的模式。值的类型为CupertinoTimerPickerMode,默认为CupertinoTimerPickerMode.HOUR_MINUTE_SECOND

item_extent

所有子元素的统一高度。默认为 32

second_interval

秒钟滚轮的粒度。必须是 60 的正整数因子。默认为 1

minute_interval

分钟滚轮的粒度。必须是 60 的正整数因子。默认为 1

value

倒计时计时器的初始持续时间(以秒为单位)。默认为 0

事件

on_change

当计时器持续时间更改时触发。