Python:使用 HTML GUI 创建桌面应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32483246/
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-08-19 11:39:35  来源:igfitidea点击:

Python: Creating desktop application with HTML GUI

python

提问by SomethingSomething

This question is more about methodology.

这个问题更多的是关于方法论。

I want to create a Python desktop application, but I don't want its GUI to be like tkinteror like PyQt. I prefer to have a beautiful and modern client GUI like Bootstrap.

我想创建一个 Python 桌面应用程序,但我不希望它的 GUI 像tkinter或像PyQt。我更喜欢像Bootstrap这样漂亮的现代客户端 GUI 。

Is there any existing API for creating such applications in Python?

是否有任何现有的 API 可用于在 Python 中创建此类应用程序?

If not: does it sound a sane workround to use some Python server (like Djangoor like web2py), and to start a new server each time the application is launched by a user, just for enabling the application core to be in Python and the client to be in HTML? Does anyone work this way?

如果不是:使用某些 Python 服务器(如Djangoweb2py),并在每次用户启动应用程序时启动一个新服务器,只是为了使应用程序核心能够在 Python 中运行,这听起来是否合理?客户端要在 HTML 中?有人这样工作吗?

采纳答案by David K. Hess

Use PyQt or PySide 2, Qt WebEngine and Qt's builtin support for hosting HTML applications:

使用 PyQt 或 PySide 2、Qt WebEngine 和 Qt 的内置支持来托管 HTML 应用程序:

http://doc.qt.io/qt-5/qtwebchannel-index.html

http://doc.qt.io/qt-5/qtwebchannel-index.html

The general architecture is a SPA (Single Page Application) running from local HTML and Javascript content bundled with your app?–?no need for bundling in a web server.

一般架构是一个 SPA(单页应用程序),从本地 HTML 和 Javascript 内容与您的应用程序捆绑在一起运行?不需要捆绑在 Web 服务器中。

For anything complicated (like bypassing cross origin issues), use the Qt WebChannel to message to functionality built on the Python side.

对于任何复杂的事情(例如绕过跨源问题),请使用 Qt WebChannel 向在 Python 端构建的功能发送消息。

This is basically the same architecture that Cordova uses.

这与 Cordova 使用的架构基本相同。

Now, whether you shouldbuild an application this way (coughQML cough) is a completely different topic.

现在,您是否应该以这种方式构建应用程序(QML咳咳)是一个完全不同的话题。

回答by Martin P. Hellwig

There is value in having a local server that does your GUI work, whether this applies in your case depends very much on the requirements of the app. Most apps I write tend to have a habit of ending up to be multi-user and hosted, so for me it makes absolute sense starting of like this.

拥有一个本地服务器来完成您的 GUI 工作是有价值的,这是否适用于您的情况在很大程度上取决于应用程序的要求。我编写的大多数应用程序都倾向于最终成为多用户和托管的应用程序,所以对我来说,从这样开始是绝对有意义的。

If you are going down this route also have a look at http://brython.info/, having the same like languages across everything makes brain context switching less of an 'overhead' (pardon the pun).

如果您要沿着这条路线走下去,还可以查看http://brython.info/,在所有内容中使用相同的语言可以减少大脑上下文切换的“开销”(请原谅双关语)。