Home > Article > Backend Development > Flet: a cross-platform Flutter-based Python framework
I just posted a micro-headline about the complete collection of Python desktop development libraries yesterday, and my colleague discovered the Flet library. This is a very new library. The first version was only released in June this year. Although it is very new, it is backed by the giant Flutter and allows us to use Python to develop full-platform software. Although it does not currently support all platforms, According to the author’s plan, whatever Flutter supports, it will support in the future. I briefly studied it yesterday and it’s really great. I recommend it to everyone. We can use it to do a series of things later.
Flet is a framework that allows building interactive multi-user web, desktop and mobile applications in your favorite language without having to have experience with front-end development.
Apps for your team, weekend projects, data entry forms, kiosk applications or high-fidelity prototypes of in-house tools or dashboards - Flet is an ideal framework for quickly hacking together a beautiful, interactive application that serves a group of users.
No more complex architecture with JavaScript frontend, REST API backend, database, cache, etc. With Flet, you can get a multi-user real-time single-page application (SPA) simply by writing a monolithic stateful application in Python.
To start developing with Flet, all you need is your favorite IDE or text editor. No SDK, no thousands of dependencies, no complex tools - Flet has a built-in web server that includes managed assets and a desktop client.
Flet UI is built with Flutter so your app looks professional and ready to be delivered to any platform. Flet simplifies the Flutter model by combining smaller "widgets" into ready-to-use "controls" with an imperative programming model.
Flet is language agnostic, so anyone on your team can develop Flet applications in their favorite language. Python is already supported, with Go, C# and other products not far behind .
Deploy your Flet app as a web app and view it in a browser. Package it as a standalone desktop application for Windows, macOS, and Linux. Install it as a PWA on your mobile device or view it via the Flet app for iOS and Android.
pip install flet
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)
Run the program:
python counter.py
How We want it to run only on the browser side, which can be configured as follows:
flet.app(target=main, view=flet.WEB_BROWSER)
The default is to run the desktop side, but when we start it, a web server will be started on a random port, which can also be accessed on the web side.
This is a simple example given by the official. Let’s write a slightly more complicated one: a calculator.
The page has a lot of code, but it is quite simple, so I won’t post it. You can see that even if you use native controls to spell out the page, the effect is pretty good, which is better than other Python Desktop development libraries are much nicer to look at. Although it does not have an interface designer like QT, which can generate pages by dragging and dropping, its layout method is the same as that of the front-end, so it is very familiar to developers who know the front-end and is very convenient to use.
At present, this project is only a BETA version, and the official documentation is not complete enough, but it is still no problem for developing some basic software. Especially based on Flutter, there is no need to package the chromium core like Electron. After accessing multiple languages later, it will provide many programmers with an excellent cross-platform development method. They do not need a specific development language to get started like Electron and Flutter. We look forward to it becoming more complete. Later we can try some more gadgets to practice our skills.
The above is the detailed content of Flet: a cross-platform Flutter-based Python framework. For more information, please follow other related articles on the PHP Chinese website!