PyCon Italy 2025-05-30
Talk: Building real-time apps for web, mobile & desktop in Python
Links:
- https://flet.dev/
- https://github.com/flet-dev/flet
- Flet Controls gallery
- Create package for Android
- Create package for IOS
- https://www.scylladb.com/
Reach out:
- email: hello(at)attilatoth(dot)dev
- https://www.linkedin.com/in/attilapm/
DEMO I did during the talk:
Run your first Flet app Link to heading
Pre-requisites Link to heading
- Python 3
- Virtual environment
Create Flet app Link to heading
Install Flet:
pip install flet
Create a new Flet project:
flet create
Run the app:
flet run
Create a new file (example.py
) and add this Flet code:
import flet as ft
def main(page):
page.adaptive = True
page.appbar = ft.AppBar(
leading=ft.TextButton("New", style=ft.ButtonStyle(padding=0)),
title=ft.Text("Adaptive AppBar"),
actions=[
ft.IconButton(ft.CupertinoIcons.ADD, style=ft.ButtonStyle(padding=0))
],
bgcolor=ft.Colors.with_opacity(0.04, ft.CupertinoColors.SYSTEM_BACKGROUND),
)
page.navigation_bar = ft.NavigationBar(
destinations=[
ft.NavigationBarDestination(icon=ft.Icons.EXPLORE, label="Explore"),
ft.NavigationBarDestination(icon=ft.Icons.COMMUTE, label="Commute"),
ft.NavigationBarDestination(
icon=ft.Icons.BOOKMARK_BORDER,
selected_icon=ft.Icons.BOOKMARK,
label="Bookmark",
),
],
border=ft.Border(
top=ft.BorderSide(color=ft.CupertinoColors.SYSTEM_GREY2, width=0)
),
)
page.add(
ft.SafeArea(
ft.Column(
[
ft.Checkbox(value=False, label="Dark Mode"),
ft.Text("First field:"),
ft.TextField(keyboard_type=ft.KeyboardType.TEXT),
ft.Text("Second field:"),
ft.TextField(keyboard_type=ft.KeyboardType.TEXT),
ft.Switch(label="A switch"),
ft.FilledButton(content=ft.Text("Adaptive button")),
ft.Text("Text line 1"),
ft.Text("Text line 2"),
ft.Text("Text line 3"),
]
)
)
)
ft.app(main)
Run this new app:
flet run example.py
Create APK for Android Link to heading
Build APK:
flet build apk
Now, you just need to install the APK on an Android device.
Install Waydroid (if you are on Linux): https://docs.waydro.id/usage/install-on-desktops
Install the app:
waydroid app install
Change window size in Waydroid (if needed):
waydroid prop set persist.waydroid.width 200
waydroid prop set persist.waydroid.height 600
sudo waydroid restart waydroid-container