Page
Page is a container for View
controls.
A page instance and the root view are automatically created when a new user session started.
Properties
auto_scroll
True
if scrollbar should automatically move its position to the end when children updated. Must be False
for scroll_to()
method to work.
appbar
An AppBar
control to display at the top of the Page.
banner
A Banner
control to display at the top of the Page.
bgcolor
Background color of the Page.
A color value could be a hex value in #ARGB
format (e.g. #FFCC0000
), #RGB
format (e.g. #CC0000
) or a named color from flet.colors
module.
bottom_appbar
BottomAppBar
control to display at the bottom of the Page. If both bottom_appbar
and navigation_bar
properties are provided, NavigationBar
will be displayed.
bottom_sheet
BottomSheet
control to display.
client_ip
🌎 Web only. IP address of the connected user.
client_user_agent
🌎 Web only. Browser details of the connected user.
controls
A list of Controls to display on the Page.
For example, to add a new control to a page:
- Python
page.controls.append(ft.Text("Hello!"))
page.update()
or to get the same result as above using page.add()
shortcut method:
- Python
page.add(ft.Text("Hello!"))
To remove the top most control on the page:
- Python
page.controls.pop()
page.update()
dark_theme
Customizes the theme of the application when in dark theme mode.
Value is an instance of the Theme()
class - more information in the theming guide.
debug
True
if Flutter client of Flet app is running in debug mode.
design
Reserved for future use.
dialog
An AlertDialog
control to display.
drawer
A NavigationDrawer
control to display as a panel sliding from the start edge of the page.
end_drawer
A NavigationDrawer
control to display as a panel sliding from the end edge of the page.
floating_action_button
A FloatingActionButton
control to display on top of Page content.
floating_action_button_location
Defines a position for the FloatingActionButton
.
Property value is FloatingActionButtonLocation
enum. Default is END_FLOAT
.
fonts
Allows importing custom fonts and use them with Text.font_family
or apply to the entire app via theme.font_family
.
The following font formats can be used with Flet:
.ttc
.ttf
.otf
The value of fonts
property is a dictionary where key is the font family name to refer that font and the value is the URL of the font file to import.
Font can be imported from external resource by providing an absolute URL or from application assets by providing relative URL and assets_dir
.
Specify assets_dir
in flet.app()
call to set the location of assets that should be available to the application. assets_dir
could be a relative to your main.py
directory or an absolute path. For example, consider the following program structure:
/assets
/fonts
/OpenSans-Regular.ttf
main.py
Now, the following program loads "Kanit" font from GitHub and "Open Sans" from the assets. "Kanit" is set as a default app font and "Open Sans" is used for a specific Text control:
import flet as ft
def main(page: ft.Page):
page.fonts = {
"Kanit": "https://raw.githubusercontent.com/google/fonts/master/ofl/kanit/Kanit-Bold.ttf",
"Open Sans": "/fonts/OpenSans-Regular.ttf"
}
page.theme = Theme(font_family="Kanit")
page.add(
ft.Text("This is rendered with Kanit font"),
ft.Text("This is Open Sans font example", font_family="Open Sans")
)
ft.app(target=main, assets_dir="assets")
At the moment only static fonts are supported, i.e. fonts containing only one spacific width/weight/style combination, for example "Open Sans Regular" or "Roboto Bold Italic".
Variable fonts support is still work in progress.
However, if you need to use a variable font in your app you can create static "instantiations" at specific weights using fonttools, then use those:
fonttools varLib.mutator ./YourVariableFont-VF.ttf wght=140 wdth=85
To explore available font features (e.g. possible options for wght
) use Wakamai Fondue online tool.
height
A height of a web page or content area of a native OS window containing Flet app. This property is read-only. It's usually being used inside page.on_resize
handler.
horizontal_alignment
How the child Controls should be placed horizontally.
Property value is CrossAxisAlignment
enum. Default is START
.
locale_configuration
A locale configuration for the app. Value is an instance of LocaleConfiguration
class which has the following
properties:
supported_locales
- a list ofLocale
s that the app plans to support. If the provided value isNone
or list is empty, this property internally defaults to[Locale("en", "US")]
(American English locale) by default.current_locale
- the currentLocale
of the app. If the provided locale is not present insupported_locales
, then this property will be set tosupported_locales[0]
(the first item of the list).
Locale
class has the following properties:
language_code
- the language code of the locale.country_code
- the country code of the locale.script_code
- the script code of the locale.
media
Provides details about app media (screen, window). See MediaQueryData in Flutter docs for more info.
The value of this property is an instance of PageMediaData
class with the following fields:
padding
(ofPadding
type) - The parts of the display that are partially obscured by system UI, typically by the hardware display "notches" or the system status bar.view_padding
(ofPadding
type) - The parts of the display that are partially obscured by system UI, typically by the hardware display "notches" or the system status bar.view_insets
(ofPadding
type) - The parts of the display that are completely obscured by system UI, typically by the device's keyboard.
In the most cases you should be fine by wrapping your content into SafeArea
control.
🎬 Watch this video explaining padding
, view_padding
and view_insets
.
name
Page name as specified in ft.app()
call. Page name is set when Flet app is running as web app. This is a portion of the URL after host name.
navigation_bar
NavigationBar
control to display at the bottom of the page. If both bottom_appbar
and navigation_bar
properties are provided, NavigationBar
will be displayed.
on_scroll_interval
Throttling in milliseconds for on_scroll
event. Default is 10
.
overlay
A list of Control
s displayed as a stack on top of main page contents.
padding
A space between page contents and its edges. Default value is 10 pixels from each side. To set zero padding:
- Python
page.padding = 0
page.update()
Padding is an instance of padding.Padding
class.
platform
Operating system the application is running on.
Property value is PagePlatform
enum with the following values:
IOS
ANDROID
MACOS
WINDOWS
LINUX
This property can be used to create adaptive UI with different controls depending on the operating system:
def main(page: ft.Page):
if page.platform == ft.PagePlatform.MACOS:
page.add(ft.CupertinoDialogAction("Cupertino Button"))
else:
page.add(ft.TextButton("Material Button"))
You can also set this property for testing purposes:
import flet as ft
def main(page):
def set_android(e):
page.platform = ft.PagePlatform.ANDROID
page.update()
print("New platform:", page.platform)
def set_ios(e):
page.platform = "ios"
page.update()
print("New platform:", page.platform)
page.add(
ft.Switch(label="Switch A", adaptive=True),
ft.ElevatedButton("Set Android", on_click=set_android),
ft.ElevatedButton("Set iOS", on_click=set_ios),
)
print("Default platform:", page.platform)
ft.app(target=main)
platform_brightness
The current brightness mode of the host platform: ft.Brightness.LIGHT
or ft.Brightness.DARK
. Read-only.
pubsub
A simple PubSub implementation for passing messages between app sessions.
subscribe(handler)
Subscribe current app session for broadcast (no topic) messages. handler
is a function or method with a single message
argument, for example:
def main(page: ft.Page):
def on_broadcast_message(message):
print(message)
page.pubsub.subscribe(on_broadcast_message)
subscribe_topic(topic, handler)
Subscribe current app session to a specific topic. handler
is a function or method with two arguments: topic
and message
, for example:
def main(page: ft.Page):
def on_message(topic, message):
print(topic, message)
page.pubsub.subscribe_topic("general", on_message)
send_all(message)
Broadcast message to all subscribers. message
could be anything: a simple literal or a class instance, for example:
@dataclass
class Message:
user: str
text: str
def main(page: ft.Page):
def on_broadcast_message(message):
page.add(ft.Text(f"{message.user}: {message.text}"))
page.pubsub.subscribe(on_broadcast_message)
def on_send_click(e):
page.pubsub.send_all(Message("John", "Hello, all!"))
page.add(ft.ElevatedButton(text="Send message", on_click=on_send_click))
send_all_on_topic(topic, message)
Send message to all subscribers on specific topic.
send_others(message)
Broadcast message to all subscribers except sender.
send_others_on_topic(topic, message)
Send message to all subscribers on specific topic except sender.
unsubscribe()
Unsubscribe current app session from broadcast messages, for example:
@dataclass
class Message:
user: str
text: str
def main(page: ft.Page):
def on_leave_click(e):
page.pubsub.unsubscribe()
page.add(ft.ElevatedButton(text="Leave chat", on_click=on_leave_click))
unsubscribe_topic(topic)
Unsubscribe current app session from specific topic.
unsubscribe_all()
Unsubscribe current app session from broadcast messages and all topics, for example:
def main(page: ft.Page):
def client_exited(e):
page.pubsub.unsubscribe_all()
page.on_close = client_exited
pwa
True
if the application is running as Progressive Web App (PWA). Read-only.
query
A part of app URL after ?
. The value is an instance of QueryString
with helper methods for fetching query parameters.
route
Get or sets page's navigation route. See Navigation and routing section for more information and examples.
rtl
True
to set text direction to right-to-left. Default is False
.
scroll
Enables a vertical scrolling for the Page to prevent its content overflow.
Property value is an optional ScrollMode
enum with None
as default.
session
A simple KV storage for session data.
session_id
A unique ID of user's session. This property is read-only.
spacing
Vertical spacing between controls on the Page. Default value is 10 virtual pixels. Spacing is applied only when alignment
is set to start
, end
or center
.
splash
A Control
that will be displayed on top of Page contents. ProgressBar
or ProgressRing
could be used as an indicator for some lengthy operation, for example:
- Python
from time import sleep
import flet as ft
def main(page: ft.Page):
def button_click(e):
page.splash = ft.ProgressBar()
btn.disabled = True
page.update()
sleep(3)
page.splash = None
btn.disabled = False
page.update()
btn = ft.ElevatedButton("Do some lengthy task!", on_click=button_click)
page.add(btn)
ft.app(target=main)
show_semantics_debugger
True
turns on an overlay that shows the accessibility information reported by the framework.
theme
Customizes the theme of the application when in light theme mode. Currently, a theme can only be automatically generated from a "seed" color. For example, to generate light theme from a green color.
Value is an instance of the Theme()
class - more information in the theming guide.
theme_mode
Page theme.
The value is ThemeMode
enum. Default is SYSTEM
.
title
A title of browser or native OS window, for example:
- Python
page.title = "My awesome app"
page.update()
url
The complete web app's URL.
vertical_alignment
How the child Controls should be placed vertically.
Property value is MainAxisAlignment
enum.
For example, MainAxisAlignment.START
, the default, places the children at the top of a Page.
views
A list of View
controls to build navigation history.
The last view in the list is the one displayed on a page.
The first view is a "root" view which cannot be popped.
web
True
if the application is running in the web browser.
width
A width of a web page or content area of a native OS window containing Flet app. This property is read-only. It's usually being used inside page.on_resize
handler.
window_always_on_top
🖥️ Desktop only. Sets whether the window should show always on top of other windows. Default is False
.
window_bgcolor
🖥️ Desktop only. Sets background color of an application window.
Use together with page.bgcolor
to make a window transparent:
import flet as ft
def main(page: ft.Page):
page.window_bgcolor = ft.colors.TRANSPARENT
page.bgcolor = ft.colors.TRANSPARENT
page.window_title_bar_hidden = True
page.window_frameless = True
page.window_left = 400
page.window_top = 200
page.add(ft.ElevatedButton("I'm a floating button!"))
ft.app(target=main)
window_focused
🖥️ Desktop only. Set to True
to focus a native OS window with a Flet app.
window_frameless
🖥️ Desktop only. Set to True
to make app window frameless.
window_full_screen
🖥️ Desktop only. Set to True
to switch app's native OS window to a fullscreen mode. Default is False
.
window_height
🖥️ Desktop only. Get or set the height of a native OS window containing Flet app.
window_left
🖥️ Desktop only. Get or set a horizontal position of a native OS window - a distance in virtual pixels from the left edge of the screen.
window_maximizable
🖥️ Desktop only. Set to False
to hide/disable native OS window's "Maximize" button. Default is True
.
window_maximized
🖥️ Desktop only. True
if a native OS window containing Flet app is maximized; otherwise False
. Set this property to True
to programmatically maximize the window and set it to False
to unmaximize it.
window_max_height
🖥️ Desktop only. Get or set the maximum height of a native OS window containing Flet app.
window_max_width
🖥️ Desktop only. Get or set the maximum width of a native OS window containing Flet app.
window_minimizable
🖥️ Desktop only. Set to False
to hide/disable native OS window's "Minimize" button. Default is True
.
window_minimized
🖥️ Desktop only. True
if a native OS window containing Flet app is minimized; otherwise False
. Set this property to True
to programmatically minimize the window and set it to False
to restore it.
window_min_height
🖥️ Desktop only. Get or set the minimum height of a native OS window containing Flet app.
window_min_width
🖥️ Desktop only. Get or set the minimum width of a native OS window containing Flet app.
window_movable
🖥️ Desktop only. macOS only. Set to False
to prevent user from changing a position of a native OS window containing Flet app. Default is True
.
window_opacity
🖥️ Desktop only. Sets the opacity of a native OS window. The value must be between 0.0
(fully transparent) and 1.0
(fully opaque).
window_resizable
🖥️ Desktop only. Set to False
to prevent user from resizing a native OS window containing Flet app. Default is True
.
window_title_bar_hidden
🖥️ Desktop only. Set to True
to hide window title bar. See WindowDragArea
control that allows moving
an app window with hidden title bar.
window_title_bar_buttons_hidden
🖥️ Desktop only. Set to True
to hide window action buttons when a title bar is hidden. macOS only.