以浏览器为界面的 Python 桌面应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2611910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 01:04:12  来源:igfitidea点击:

Python Desktop Application with the Browser as an interface?

pythonbrowserdesktophttpserver

提问by Eli

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

我想创建一个在用户计算机上运行的应用程序,一个独立的应用程序,带有安装和其他功能,但我希望界面是一个浏览器,在内部并显示为操作系统窗口或使用浏览器访问的外部(即一些http服务器)。

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.

原因是因为我对 Python 略知一二,但我认为只要我有一些可以使用和操作的基本根,我就可以管理,这些根将是 HTML、CSS 和 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.

我还没有找到一个可以使用的好的 GUI 工具,并且在尝试弄乱并最终没有得到任何东西后总是放弃这个想法。

采纳答案by Piotr Lesnicki

Python offers two things that should be of your interest:

Python 提供了两件您应该感兴趣的东西:

  • a web server in the standard library
  • a standartized interface for web applications, called WSGI
  • 标准库中的 Web 服务器
  • Web 应用程序的标准化接口,称为 WSGI

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 servethat launches a web server.

因此,向您的应用程序添加 Web 界面相对容易。例如,在 Mercurial(版本控制系统)中,您有一个hg serve启动 Web 服务器的命令。

To see python launching a web server, and a WSGI app, just do:

要查看 python 启动 Web 服务器和 WSGI 应用程序,只需执行以下操作:

python -m 'wsgiref.simple_server'

You can look at the wsgiref source code or some WSGI tutorial to do a simple app.

你可以查看 wsgiref 源代码或一些 WSGI 教程来做一个简单的应用程序。

After that, you may want to use a web framework (for templating & co), but that is another question...

之后,您可能想要使用网络框架(用于模板和合作),但这是另一个问题......

回答by Matthew Flaschen

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.

你可以用睡衣。它是 Google Web Toolkit 到 Python 的端口,这基本上意味着您用 Python 编写并编译为 HTML 和 JS。

回答by Alex Martelli

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.

有许多出色的 GUI 工具可用于您想要制作 GUI 的方式——HTML、CSS 和 Javascript。如果您不知道,请使用正确的标签在单独的问题中提问。

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 wantfor it?!

这样安排的 Python 端应该没有自己的 GUI,而只是运行 Python 标准库的 HTTP 服务器的一个子类,只提供 HTML、CSS 和 JS 文件,以及通过 JS 可以在其他 URL 上的 JSON 数据使用 Ajax 技术,主要是实现存储和业务逻辑——所以你可能想要什么“GUI 工具”还远非显而易见?!

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 servethem, after all.

只需使用自己的“GUI 工具”单独开发 Python 端(例如,使用 IDLE、Wingware、SPE 或任何您喜欢的东西)和 HTML/CSS/Javascript。毕竟,Python 对这些文件所做的一切都是静态地它们服务

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 allthe GUI work in the browser instead.

您可能会考虑使用一些 Python 端模板,例如 Mojo &c,但我的建议是避免这种情况:相反,始终采用“瘦服务器架构”,使 Python 端成为业务逻辑和存储的 RESTful 服务器层,并在浏览器中执行所有GUI 工作。

回答by Alex Martelli

Are you resorting to a web browser only because you've had difficulty with Python widget toolkits, like Tkinter,wxpython, and pyqt?

您是否仅仅因为在使用 Python 小部件工具包(如 Tkinter、wxpython 和 pyqt)时遇到困难而求助于 Web 浏览器?

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.

你试过Qt 设计师吗?它是一个图形 GUI 设计器,可以非常快速和轻松地开发出漂亮的 GUI。它随 PyQt 自动安装。

http://www.riverbankcomputing.co.uk/software/pyqt/download

http://www.riverbankcomputing.co.uk/software/pyqt/download