Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【开源项目】flet #2336

Open
iakirago opened this issue Aug 22, 2022 · 0 comments
Open

【开源项目】flet #2336

iakirago opened this issue Aug 22, 2022 · 0 comments

Comments

@iakirago
Copy link

推荐项目

  • 项目标题:Flet 是一个使您能够轻松地以您喜欢的语言构建实时 Web、移动和桌面应用程序的框架
  • 项目描述:Flet 是一个框架,使您能够轻松地以您喜欢的语言构建实时 Web、移动和桌面应用程序,并与您的团队安全地共享它们。无需前端经验。
  • 亮点:不再需要 JavaScript 前端、REST API 后端、数据库、缓存等复杂架构。使用 Flet,您只需用 Python 编写一个整体式有状态应用程序,并获得多用户、实时单页应用程序 (SPA)。

  • 示例代码:

安装依赖包

pip install flet

编写代码

counter.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)

运行代码, 该应用程序将在本机操作系统窗口中启动 - 这是 Electron 的一个不错的替代品!
python counter.py

如果您想将应用程序作为 Web 应用程序运行,只需将最后一行替换为:
flet.app(target=main, view=flet.WEB_BROWSER)

  • 截图:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants