Skip to content

Window 继承自: BaseControl

Controls the app window.

Limitation: This control is for Desktop platforms (macOS, Windows, Linux) only.

属性 ​

名称类型默认值说明
bgcolorOptional[ColorValue]NoneSets background color of an application window. Tip: Can be used together with bgcolor to make a window transparent.
widthOptional[Number]NoneDefines the width of the app window.
heightOptional[Number]NoneDefines the height of the app window.
topOptional[Number]NoneDefines the vertical position of a native OS window - a distance in virtual pixels from the top edge of the screen.
leftOptional[Number]NoneDefines the horizontal position of the app window - a distance in virtual pixels from the left edge of the screen.
max_widthOptional[Number]NoneDefines the maximum width of the app window.
max_heightOptional[Number]NoneDefines the maximum height of the app window.
min_widthOptional[Number]NoneDefines the minimum width of the app window.
min_heightOptional[Number]NoneDefines the minimum height of the app window.
opacityNumber1.0Defines the opacity of the app window. Raises: ValueError: If it is not between 0.0 and 1.0 inclusive.
aspect_ratioOptional[Number]NoneDefines the aspect ratio of the app window.
brightnessOptional[Brightness]NoneThe brightness of a app window.
maximizedboolFalseWhether the app window is maximized. Set to True to maximize programmatically.
minimizedboolFalseWhether the app window is minimized. Set to True to minimize programmatically.
minimizableboolTrueWhether the app window can be minimized through the window's "Minimize" button.
maximizableboolTrueWhether to hide/disable app window's "Maximize" button.
resizableboolTrueWhether the app window can be resized.
movableboolTrueWhether the app window can be moved. Limitation: Has effect on macOS only.
full_screenboolFalseWhether to switch the app's window to fullscreen mode.
always_on_topboolFalseWhether the app window should always be displayed on top of other windows/apps.
always_on_bottomboolFalseWhether the app window should always be displayed below other windows. Limitation: Has effect on Linux and Windows only.
prevent_closeboolFalseSet to True to intercept the native close signal. Could be used to implement app exit confirmation logic.
skip_task_barboolFalseWhether the app window should be hidden from the Task Bar (on Windows) or Dock (on macOS).
title_bar_hiddenboolFalseWhether to hide the app window's title bar.
title_bar_buttons_hiddenboolFalseWhether to hide the app window's title bar buttons. Limitation: Has effect on macOS only.
framelessboolFalseWhether the app window should be frameless.
progress_barOptional[Number]NoneThe value from 0.0 to 1.0 to display a progress bar on Task Bar or Dock.
focusedboolTrueWhether the app window should be focused. Set to True to focus programmatically.
visibleboolTrueWhether to make the app window visible. Can be of use when the app starts as hidden.
shadowboolTrueWhether to display a shadow around the app window.
alignmentOptional[Alignment]NoneDefines the alignment of the app window.
badge_labelOptional[str]NoneSets a badge label on the app window. Limitation: Has effect on macOS only.
iconOptional[str]NoneThe icon of the app window. The file should have the .ico extension. Limitation: Has effect on Windows only.
ignore_mouse_eventsboolFalseWhether 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.
dataAnyskip_任意类型的自定义数据。
keyOptional['KeyValue']None用于在更新之间保持控件身份稳定的 key。

只读属性 ​

名称类型默认值说明
parentOptional['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_eventOptional[EventHandler[WindowEvent]]NoneCalled 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.
updateNone—请求更新该控件的 UI。 在修改控件状态或属性后调用。 控件必须已挂载到页面,并且未被冻结。

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