主题
Window 继承自: BaseControl
Controls the app window.
Limitation: This control is for Desktop platforms (macOS, Windows, Linux) only.
属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
bgcolor | Optional[ColorValue] | None | Sets background color of an application window. Tip: Can be used together with bgcolor to make a window transparent. |
width | Optional[Number] | None | Defines the width of the app window. |
height | Optional[Number] | None | Defines the height of the app window. |
top | Optional[Number] | None | Defines the vertical position of a native OS window - a distance in virtual pixels from the top edge of the screen. |
left | Optional[Number] | None | Defines the horizontal position of the app window - a distance in virtual pixels from the left edge of the screen. |
max_width | Optional[Number] | None | Defines the maximum width of the app window. |
max_height | Optional[Number] | None | Defines the maximum height of the app window. |
min_width | Optional[Number] | None | Defines the minimum width of the app window. |
min_height | Optional[Number] | None | Defines the minimum height of the app window. |
opacity | Number | 1.0 | Defines the opacity of the app window. Raises: ValueError: If it is not between 0.0 and 1.0 inclusive. |
aspect_ratio | Optional[Number] | None | Defines the aspect ratio of the app window. |
brightness | Optional[Brightness] | None | The brightness of a app window. |
maximized | bool | False | Whether the app window is maximized. Set to True to maximize programmatically. |
minimized | bool | False | Whether the app window is minimized. Set to True to minimize programmatically. |
minimizable | bool | True | Whether the app window can be minimized through the window's "Minimize" button. |
maximizable | bool | True | Whether to hide/disable app window's "Maximize" button. |
resizable | bool | True | Whether the app window can be resized. |
movable | bool | True | Whether the app window can be moved. Limitation: Has effect on macOS only. |
full_screen | bool | False | Whether to switch the app's window to fullscreen mode. |
always_on_top | bool | False | Whether the app window should always be displayed on top of other windows/apps. |
always_on_bottom | bool | False | Whether the app window should always be displayed below other windows. Limitation: Has effect on Linux and Windows only. |
prevent_close | bool | False | Set to True to intercept the native close signal. Could be used to implement app exit confirmation logic. |
skip_task_bar | bool | False | Whether the app window should be hidden from the Task Bar (on Windows) or Dock (on macOS). |
title_bar_hidden | bool | False | Whether to hide the app window's title bar. |
title_bar_buttons_hidden | bool | False | Whether to hide the app window's title bar buttons. Limitation: Has effect on macOS only. |
frameless | bool | False | Whether the app window should be frameless. |
progress_bar | Optional[Number] | None | The value from 0.0 to 1.0 to display a progress bar on Task Bar or Dock. |
focused | bool | True | Whether the app window should be focused. Set to True to focus programmatically. |
visible | bool | True | Whether to make the app window visible. Can be of use when the app starts as hidden. |
shadow | bool | True | Whether to display a shadow around the app window. |
alignment | Optional[Alignment] | None | Defines the alignment of the app window. |
badge_label | Optional[str] | None | Sets a badge label on the app window. Limitation: Has effect on macOS only. |
icon | Optional[str] | None | The icon of the app window. The file should have the .ico extension. Limitation: Has effect on Windows only. |
ignore_mouse_events | bool | False | Whether the app window should ignore mouse events, passing them to the window below it. If this window has focus, it will still receive keyboard events. |
data | Any | skip_ | 任意类型的自定义数据。 |
key | Optional['KeyValue'] | None | 用于在更新之间保持控件身份稳定的 key。 |
只读属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
parent | Optional['BaseControl'] | — | The direct ancestor(parent) of this control. It defaults to None and will only have a value when this control is mounted (added to the page tree). Page 控件(树的根)为例外 —— 它始终 parent=None。 |
page | 'Page' | — | 此控件所属的页面。 |
事件
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
on_event | Optional[EventHandler[WindowEvent]] | None | Called when app window changes its state. For example, when the window is maximized or minimized. |
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
wait_until_ready_to_show | — | — | Waits until the app window is ready to show. |
destroy | — | — | Destroys the app window. |
center | — | — | Centers the app window. |
close | — | — | Requests graceful closing of the app window. This sends a native close request equivalent to pressing the window close button. If prevent_close is enabled, the close may be intercepted and reported via on_event with CLOSE. |
to_front | — | — | Brings the app window to the front. |
start_dragging | — | — | Starts dragging the app window. |
start_resizing | — | — | Starts resizing the app window. |
is_isolated | — | — | Return whether this control is marked as isolated. 被隔离的控件不会参与父级驱动的更新遍历,需要自行管理更新边界。 |
init | — | — | Called after control instance initialization and before the first build / update cycle. 可重写此钩子执行依赖于已初始化字段的轻量设置。 不要在这里调用 update()。 |
build | — | — | 在控件初始化期间调用一次,用于定义其子控件。 page 属性在此方法中可用。 |
before_update | — | — | 每次控件即将更新时调用。 Note: 不要在此处调用 update()。 |
before_event | — | — | 在事件处理器执行前拦截事件。 返回 False 取消分发,返回 True 或 None 则继续正常的事件处理。 |
did_mount | — | — | 在控件挂载到页面树之后调用。 可重写以启动需要已挂载页面的资源,例如订阅、定时器或服务监听。 |
will_unmount | — | — | 在控件从页面树移除之前调用。 可重写以释放 did_mount() 中创建的资源,例如订阅、定时器或外部句柄。 |
get_data_channel | — | — | Resolve the [DataChannel] allocated on the Dart side for this widget. Pattern: on_data_channel_open: Optional[ft.EventHandler[DataChannelOpenEvent]] = None def init(self): self.on_data_channel_open = self._on_open def _on_open(self, e): self._channel = self.get_data_channel(e.channel_id) Idempotent — the underlying Connection caches DataChannels by id, so repeated calls return the same instance. No error path: the id always comes from a framework-fired event, so by the time this runs the channel exists on both sides. |
update | None | — | 请求更新该控件的 UI。 在修改控件状态或属性后调用。 控件必须已挂载到页面,并且未被冻结。 |