Flet add .ft and screen menager
Project description
fletft – Extensions for Flet
fletft is an extension for the Flet library, introducing new possibilities for designing user interfaces.
It allows you to define GUI structures in separate .ft (YAML) files, which simplifies code management and improves readability.
Additionally, the library offers a simple scene manager (ScreenManager) for easy switching between different application views.
✨ Features
-
GUI Design in
.ftFiles Create user interfaces using YAML syntax, separating logic from presentation. -
Screen Manager (ScreenManager) Easily manage and navigate between different application screens.
-
Component Loading Load components from
.ftfiles directly into your Flet application. -
Access Components by ID Quickly access specific components using their identifiers.
📦 Installation
pip install fletft
💡 Usage Examples
1. GUI Design with .ft File
This example demonstrates how to define your GUI layout in a ui.ft file and load it into your main Flet application.
main.py
import flet
from flet_ft import load_ui, get_by_id
# Main Flet function
def main(page: flet.Page):
# Load YAML as a string
with open("ui.ft", "r", encoding="utf-8") as f:
yaml_data = f.read()
# Pass `globals()` so the parser can access functions from this file
controls = load_ui(yaml_data, context_globals=globals())
# Add components to the page
page.controls.extend(controls)
# Access component by ID and update its text
get_by_id("test").text = 'ok'
page.update()
# Function to handle button clicks
def handle_click(e):
print("Button was clicked!")
e.page.update()
# Start the application
flet.app(target=main)
ui.ft
page:
controls:
- Column:
spacing: 20
controls:
- Text:
value: "hello fletft"
size: 32
- ElevatedButton:
text: "test"
id: "test"
on_click: handle_click
2. Screen Manager (ScreenManager)
This example demonstrates using ScreenManager to easily switch between different application screens.
app_with_screens.py
import flet as ft
from flet_ft import ScreenManager
def main(page: ft.Page):
page.title = "Screen Manager Example"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
sm = ScreenManager(page)
# Home screen
home_view = ft.Column(
[
ft.Text("🏠 Home Screen", size=30, weight=ft.FontWeight.BOLD),
ft.ElevatedButton("Go to About", on_click=lambda e: sm.set_current("about")),
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER
)
# About screen
about_view = ft.Column(
[
ft.Text("ℹ️ About Screen", size=30, weight=ft.FontWeight.BOLD),
ft.ElevatedButton("Back to Home", on_click=lambda e: sm.set_current("home")),
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER
)
# Add screens to the manager
sm.add_screen("home", home_view)
sm.add_screen("about", about_view)
# Set the initial screen
sm.set_current("home")
ft.app(target=main)
🔗 Links
- Original Flet project: https://flet.dev
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fletft-0.0.3.tar.gz.
File metadata
- Download URL: fletft-0.0.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5691f60c79a36d6365c240f700c40dd95c939b12235239f0843f10156372914b
|
|
| MD5 |
2a87e1d5af1cfdeb16c7a7723d78b4fc
|
|
| BLAKE2b-256 |
a50aeeb72691613d67e7a372dcc7ae4431033557e459b29e868f4a8d3720b2c7
|
File details
Details for the file fletft-0.0.3-py3-none-any.whl.
File metadata
- Download URL: fletft-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e055f3f12eb79a438445ab3c95f6f4f706081976e6833b8f4f28917fb269a85e
|
|
| MD5 |
70980d66207bc684c4a0b1cbb986d240
|
|
| BLAKE2b-256 |
4514cffcf592721ead19255ac162ca1cf37b2c88a1cdb4290a7a58bf8e5d265d
|