Skip to main content

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 .ft Files 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 .ft files 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

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

fletft-0.0.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fletft-0.0.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file fletft-0.0.4.tar.gz.

File metadata

  • Download URL: fletft-0.0.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for fletft-0.0.4.tar.gz
Algorithm Hash digest
SHA256 55c42e80970ce3e84c12da883fdc36bef044a4c9519b554d304b76475c3e3348
MD5 91db08bb5189b5646b6b90f84fdfec05
BLAKE2b-256 12209fc88a19c96427e535d4ec0bc0922c6574e92c19f70f83e9eb3b269b9797

See more details on using hashes here.

File details

Details for the file fletft-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: fletft-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for fletft-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 dee38824412b4100fd809978fb4e41cdb236d722978f65ba0a329f6f393ebd1c
MD5 d21ca649ebdee07486e2d2ab681a2da5
BLAKE2b-256 51428b671c2e8b7c1b01a1de563eebb30d0f8c2a3e921428226c45a92ce55f17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page