FlexxPython 的 GUI 开发工具

联合创作 · 2023-09-28 06:41

Flexx 是一个纯 Python 工具包,用来创建图形化界面应用程序。其使用 Web 技术进行界面的渲染。你可以用 Flexx 来创建桌面应用,同时也可以导出一个应用到独立的 HTML 文档。因为使用纯 Python 开发,所以 Flexx 是跨平台的。只需要有 Python 和浏览器就可以运行。如果是使用桌面模式运行,推荐使用 Firefox 。

Flexx 使用模块化设计,包含一些子系统:

  • ui - UI 部件

  • app - 事件循环和服务器

  • react - reactive 编程

  • pyscript - Python to JavaScript transpiler

  • webruntime - to launch a runtime

示例代码:

from flexx import app, ui, react

class Example(ui.Widget):

    def init(self):
        self.count = 0
        with ui.HBox():
            self.button = ui.Button(text='Click me', flex=0)
            self.label = ui.Label(flex=1)

    @react.connect('button.mouse_down')
    def _handle_click(self, down):
        if down:
            self.count += 1
            self.label.text('clicked %i times' % self.count)

main = app.launch(Example)
app.run()
浏览 8
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报