DEV Community

Cover image for Create app with Flet on python
watchakorn-18k
watchakorn-18k

Posted on

Create app with Flet on python

Image description

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.

Flet UI is built with Flutter, so your app looks professional and can be delivered to any platform. Flet simplifies Flutter model by combining smaller "widgets" into ready-to-use "controls" with imperative programming model.

To run the app install flet module:

pip install flet
Enter fullscreen mode Exit fullscreen mode

Flet app example

  • create file app.py
import flet
from flet import IconButton, Page, Row, TextField, icons

def main(page: Page):
    page.title = "Flet counter example"
    page.vertical_alignment = "center"

    txt_number = TextField(value="0", text_align="right", width=100)

    def minus_click(e):
        txt_number.value = int(txt_number.value) - 1
        page.update()

    def plus_click(e):
        txt_number.value = int(txt_number.value) + 1
        page.update()

    page.add(
        Row(
            [
                IconButton(icons.REMOVE, on_click=minus_click),
                txt_number,
                IconButton(icons.ADD, on_click=plus_click),
            ],
            alignment="center",
        )
    )

flet.app(target=main)
Enter fullscreen mode Exit fullscreen mode

and run the program:

python app.py
Enter fullscreen mode Exit fullscreen mode

Image description

Now, if you want to run the app as a web app, just replace the

last line with:

flet.app(target=main, view=flet.WEB_BROWSER)
Enter fullscreen mode Exit fullscreen mode

Image description

Creating Flet apps in Python

Source

Flet Document

Discussion (0)