基于Web技术的Python UI 工具箱:Flexx

ggect 9年前

Flexx 是一个纯 Python 工具包,用来创建图形化界面应用程序。其使用 Web 技术进行界面的渲染。你可以用 Flexx 来创建桌面应用和Web应用,同时也可以导出一个应用到独立的 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()

Current status

Flexx is still very much a work in progress. Please don't go use it just yet for anything serious. The public API can change without notice. However, we're interested in feedback, so we invite you to play with it!

Getting started

  • clone the repo
  • put the repo dir in your PYTHONPATH
  • python setup.py install
  • run the examples

Demo server

There is an Amazon instance running some demos on http://52.21.93.28:8000/ (unless I turned it off for testing, etc.).

项目主页:http://www.open-open.com/lib/view/home/1441499739186