Enable Dark Mode!
how-to-create-flet-apps-using-python.jpg
By: Janish Babu EK

How to Create Flet Apps Using Python?

Technical

What is Flet?

Flet is a framework that lets you build interactive multi-consumer net, computing device, and cell applications on your favored language without prior experience in frontend improvement.

You assemble a UI to your software program with Flet controls, which might be totally based on Flutter by means of Google. Flet does not just "wrap" Flutter widgets, it affords its very own "opinion" through combining smaller widgets, hiding complexities, imposing UI pleasant-practices, utilizing low-priced defaults - all to make sure your app's appearance is cool and professional without extra effort.

Flet app example

To run the app, deploy the Flet module:

pip install flet

Here is a sample "Counter" app:

counter.py

import flet as ft
def main(page: ft.Page):
    page.title = "Cybrosys counter example"
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    text_value = ft.TextField(value="0", text_align=ft.TextAlign.RIGHT, width=100)
    def minus_value(e):
        text_value.value = str(int(text_value.value) - 1)
        page.update()
    def plus_value(e):
        text_value.value = str(int(text_value.value) + 1)
        page.update()
    page.add(
        ft.Row(
            [
                ft.IconButton(ft.icons.REMOVE, on_click=minus_value),
                text_value,
                ft.IconButton(ft.icons.ADD, on_click=plus_value),
            ],
            alignment=ft.MainAxisAlignment.CENTER,
        )
    )
ft.app(target=main)

Run this system:

python counter.py

The app might begin in a local OS window - what a pleasant alternative to Electron!

* Windows          

how-to-create-flet-apps-using-python-1-cybrosys

* OS

how-to-create-flet-apps-using-python-2-cybrosys

Now, if you want to run the app as a web app, simply update the closing line with:

ft.app(target=main, view=ft.AppView.WEB_BROWSER)

Run once more, and now you instantly get a web app:

Creating Flet apps in Python

On this guide we're going to take a look at the structure of a Flet app, learn how to output records using Flet controls, request data from a user and build basic page layouts.

We also can cover some packaging and deployment alternatives to deliver a prepared app in your customers.

Installing the Flet module

Flet requires Python 3.7.0 or above. First of all Flet, you need to install flet module first:

pip install flet

To upgrade the flet module, run:

pip install flet --upgrade

To install Flet pre-release (for advanced users) run:

pip install flet --pre

To install GStreamer on Ubuntu/Debian run the subsequent commands:

sudo apt-get update
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

Basic App Structure

A very minimal Flet app has the following shape:

import flet as ft
def main(page: ft.Page):
    # add/update controls on Page
    pass
ft.app(target=main)

Internally, each the app can be started out in a native OS window - what a pleasant alternative to Electron! . The Flet internet server is known as "Fletd" and by default it is listening on a random TCP port. You can specify a custom TCP port and then open the app inside the browser at the side of laptop view:

flet(port=8550, target=main)

Open http://localhost:<port> in your browser to look at the web version of your Flet app.


If you need any assistance in odoo, we are online, please chat with us.



1
Comments

Saschaya Pranev

Thanks for the guidance! Excited to create Flet apps with Python.

27/09/2023

-

1:20PM



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message