Skip to content

WindowEventType 继承自: Enum

原生桌面窗口事件的类型。

这些值通过 type 字段报告,并由 on_event 传递。事件是否可用取决于操作系统及底层窗口管理器。

示例 ​

python
import flet as ft


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

    log = ft.Column(
        spacing=4,
        scroll=ft.ScrollMode.AUTO,
        height=220,
    )

    def add_log(message: str):
        log.controls.insert(0, ft.Text(message, size=12))
        if len(log.controls) > 20:
            log.controls.pop()
        log.update()

    def on_window_event(e: ft.WindowEvent):
        add_log(f"Received: {e.type.name}")

    page.window.on_event = on_window_event

    page.appbar = ft.AppBar(title="WindowEventType Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Interact with the app window and watch incoming event types."
                    ),
                    ft.Text(
                        "Desktop only. Try focus, blur, resize, move, "
                        "minimize, maximize.",
                        size=11,
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=8,
                        controls=[
                            ft.Container(
                                padding=ft.Padding.symmetric(horizontal=8, vertical=4),
                                border=ft.Border.all(1, ft.Colors.OUTLINE),
                                border_radius=12,
                                content=ft.Text(event_type.name, size=11),
                            )
                            for event_type in ft.WindowEventType
                        ],
                    ),
                    ft.Container(
                        width=720,
                        padding=12,
                        border=ft.Border.all(1, ft.Colors.RED),
                        border_radius=10,
                        bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
                        content=log,
                    ),
                ],
            ),
        )
    )


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

枚举值 ​

名称类型默认值说明
CLOSE—'close'The OS requested the window to close.
FOCUS—'focus'The window became focused.
BLUR—'blur'The window lost focus.
HIDE—'hide'The window became hidden.
SHOW—'show'The window became visible.
MAXIMIZE—'maximize'The window was maximized.
UNMAXIMIZE—'unmaximize'The window exited maximized state.
MINIMIZE—'minimize'The window was minimized.
RESTORE—'restore'The window was restored from a minimized state.
RESIZE—'resize'The window size is changing.
RESIZED—'resized'The window size changed.
MOVE—'move'The window position is changing.
MOVED—'moved'The window position changed.
LEAVE_FULL_SCREEN—'leave-full-screen'The window exited full-screen mode.
ENTER_FULL_SCREEN—'enter-full-screen'The window entered full-screen mode.

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