Flet for Python
Flet is a Python library for easily building interactive multi-platform apps using Flutter under the hood. It allows developers to create beautiful desktop, web, and mobile applications with pure Python, leveraging a declarative UI framework. Currently at version 0.84.0, Flet maintains a rapid release cadence, often with weekly development builds and bi-weekly stable releases.
Warnings
- gotcha After modifying any control's properties (e.g., `text_control.value = 'new_value'`), you must call `page.update()` (or `control.update()`, `view.update()`) for changes to be reflected in the UI. Forgetting this is a very common beginner mistake.
- breaking In version 0.83.1, properties `delta_x` and `delta_y` in certain event objects (e.g., for mouse events) were replaced with `local_delta.x` and `local_delta.y`. Code relying on the old properties will break.
- gotcha Due to rapid development, Flet's API can change frequently, especially for control properties and event signatures. Code written for one minor version might require adjustments for a newer one.
- gotcha Packaging Flet applications into standalone executables using `flet pack` can sometimes be platform-specific or encounter build issues, particularly on macOS, as noted in recent development releases.
Install
-
pip install flet
Imports
- ft
import flet as ft
- app
ft.app(target=main)
- Page
from flet import Page
def main(page: ft.Page):
Quickstart
import flet as ft
def main(page: ft.Page):
page.title = "Flet Counter App"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
txt_number = ft.Text("0", size=30)
def minus_click(e):
txt_number.value = str(int(txt_number.value) - 1)
page.update()
def plus_click(e):
txt_number.value = str(int(txt_number.value) + 1)
page.update()
page.add(
ft.Row(
[
ft.IconButton(ft.icons.REMOVE, on_click=minus_click),
txt_number,
ft.IconButton(ft.icons.ADD, on_click=plus_click),
],
alignment=ft.MainAxisAlignment.CENTER,
)
)
ft.app(target=main)