使用浏览器作为界面的 Python 桌面应用程序?
我想创建一个在用户计算机上运行的应用程序,一个独立的应用程序,带有安装和其他功能,但我希望界面是一个浏览器,可以是内部的并显示为操作系统窗口,也可以使用浏览器进行外部访问(即一些http服务器)。
原因是因为我对 Python 有一点了解,但我认为只要我有一些可以使用和操作的基本根,我就可以管理,这些根是 HTML、CSS 和 Javascript。
我还没有找到一个可以使用的好的 GUI 工具,并且总是在尝试混乱并最终一无所获后放弃这个想法。
I want to create an application that runs on the users computer, a stand-alone application, with installation and what-not, but I want the interface to be a browser, either internal and displayed as an OS window or external accessible using the browser (i.e. some http server).
The reason would be because I know a little about Python, but I think I can manage as long as I have some basic roots that I can use and manipulate, and those would be HTML, CSS, and Javascript.
I've yet to find a good GUI tool which I can use, and always abandon the idea after trying to mess around and eventually not getting anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Python 提供了您应该感兴趣的两件事:
因此,向应用程序添加 Web 接口相对容易。例如,在 Mercurial(版本控制系统)中,您有一个启动 Web 服务器的命令
hgserve
。要查看 python 启动 Web 服务器和 WSGI 应用程序,只需执行以下操作:
您可以查看 wsgiref 源代码或一些 WSGI 教程来制作一个简单的应用程序。
之后,您可能想使用 Web 框架(用于模板化和协作),但这是另一个问题......
Python offers two things that should be of your interest:
So it is relatively easy to add a web interface to your application. For example in Mercurial (the versioning system), you have a command
hg serve
that launches a web server.To see python launching a web server, and a WSGI app, just do:
You can look at the wsgiref source code or some WSGI tutorial to do a simple app.
After that, you may want to use a web framework (for templating & co), but that is another question...
您可以使用睡衣。它是 Google Web Toolkit 到 Python 的端口,这基本上意味着您用 Python 编写,然后它会被编译为 HTML 和 JS。
You could use Pyjamas. It's a port of Google Web Toolkit to Python, which basically means you write in Python and it gets compiled to HTML and JS.
有很多优秀的 GUI 工具可以满足您想要的 GUI 方式——HTML、CSS 和 Javascript。如果您不知道任何问题,请使用正确的标签提出单独的问题。
在这种安排中,Python 端不应该有自己的 GUI,而只是运行 Python 标准库的 HTTP 服务器的子类,仅提供 HTML、CSS 和 JS 文件,以及通过 JS 可以访问的其他 URL 上的 JSON 提供的数据通过 Ajax 技术实现,本质上是实现存储和业务逻辑 —— 因此,您可能想要使用什么“GUI 工具”还远不清楚?!
只需使用自己的“GUI 工具”单独开发Python 端(例如,使用IDLE、Wingware、SPE 或任何您喜欢的东西)和HTML/CSS/Javascript。毕竟,Python 对这些文件所做的只是静态地服务它们。
您可能会考虑使用一些 Python 端模板,例如 Mojo &c,但我的建议是避免这种情况:相反,始终采用“瘦服务器架构”,使 Python 端成为业务逻辑的 RESTful 服务器和存储层,并在浏览器中执行所有 GUI 工作。
There are plenty of excellent GUI tools for the way you want to do your GUI -- HTML, CSS, and Javascript. If you don't know of any, ask in a separate question with the right tags.
The Python side in such an arrangement should have no GUI of its own, but just run a subclass of the Python's standard library's HTTP server, just serving the HTML, CSS, and JS files, and data via JSON on other URLs that the JS can reach with Ajax techniques, essentially implementing storage and business logi -- so it's far from obvious what "GUI tool" you could possibly want for it?!
Just develop the Python side on its own (e.g. with IDLE, Wingware, SPE, or whatever you like) and the HTML / CSS / Javascript separately, with its own "GUI tool". All that Python will do with those files is statically serve them, after all.
You could be thinking of using some Python side templating, such as Mojo &c, but my recommendation is to avoid that: rather, go with the "thin server architecture" all the way, make the Python side a RESTful server of business logic and storage layers, and do all the GUI work in the browser instead.
您是否仅仅因为无法使用 Python 小部件工具包(例如 Tkinter、wxpython 和 pyqt)而求助于 Web 浏览器?
您是否尝试过 Qt 设计器< /a>?它是一个图形 GUI 设计器,可以非常快速、轻松地开发美观的 GUI。它会随 PyQt 自动安装。
http://www.riverbankcomputing.co.uk/software/pyqt/download
Are you resorting to a web browser only because you've had difficulty with Python widget toolkits, like Tkinter,wxpython, and pyqt?
Have you tried Qt Designer? It's a graphical GUI designer, making it very quick and easy to develop great looking GUI's. It gets installed automatically with PyQt.
http://www.riverbankcomputing.co.uk/software/pyqt/download
一个简单的 gui 演示如何在浏览器中使用 python 进行通信:
sqr.py
sqrt.html
使用
python3 sqr.py
运行程序,并在浏览器中使用地址http://localhost:8004/sqr.html
。该示例源自如何在 Python 中实现 AJAX 的最小服务器?。
http.server
是一个内置的在Python的模块中。然而,周围应该还有许多其他工具。A simple gui demonstrating how to talk from the browser with python:
sqr.py
sqrt.html
Run the program with
python3 sqr.py
and use the addresshttp://localhost:8004/sqr.html
in the browser.The example is derived from How to implement a minimal server for AJAX in Python?.
http.server
is a built-in module of python. Yet, there should are many other tools around.