如何使用 HTML + Javascript 构建 Python GUI?

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

How can I use HTML + Javascript to build a python GUI?

pythonwebkit

提问by Lettuce

I have been experimenting with Appcelerator Titanum yesterday and I think it's cool when it comes to Javascript.

我昨天一直在试验 Appcelerator Titanum,我认为它在 Javascript 方面很酷。

Python features on Appcelerator Titanum are so limited (can't use some modules for example).

Appcelerator Titanum 上的 Python 功能非常有限(例如,无法使用某些模块)。

My question is How can I use html & javascript as a GUI tool for a real python application?

我的问题是如何使用 html 和 javascript 作为真正的 python 应用程序的 GUI 工具?

I am running windows 7 and i was thinking of using webkitfor that purpose but couldn't know how to work with it in python.

我正在运行 Windows 7,我正在考虑为此目的使用webkit,但不知道如何在 python 中使用它。

I am planning to make a standalone executable using py2exe as I don't know if the users always have python and the appropriate modules installed.

我打算使用 py2exe 制作一个独立的可执行文件,因为我不知道用户是否总是安装了 python 和适当的模块。

回答by S.Lott

So how can I use html & javascript as a gui tool for a real python application ?

那么如何使用 html 和 javascript 作为真正的 python 应用程序的 gui 工具呢?

You run a web server on your desktop. For example, this: http://docs.python.org/library/simplehttpserver.htmlIn a few lines of code you can provide a complete HTTP server that will serve your HTML and Javascript to a browser.

您在桌面上运行 Web 服务器。例如,这个:http://docs.python.org/library/simplehttpserver.html在几行代码中,您可以提供一个完整的 HTTP 服务器,它将为浏览器提供您的 HTML 和 Javascript。

I am running windows 7 and i was thinking of using webkit for that purpose but couldn't know how to work with it in python actually moreover I wanna use py2exe so how can I use python + webkit to handle the gui part ?

我正在运行 Windows 7,我正在考虑为此目的使用 webkit,但实际上我不知道如何在 python 中使用它,而且我想使用 py2exe 那么我如何使用 python + webkit 来处理 gui 部分?

Hard to parse that. It either indicates too much coffee or no familiarity with punctuation.

很难解析。它要么表示喝了太多咖啡,要么不熟悉标点符号。

Randomly, I'll pick the following words as possibly being meaningful.

随机地,我会选择以下可能有意义的词。

how can I use python + webkit to handle the gui part ?

我如何使用 python + webkit 来处理 gui 部分?

You run a web server on your desktop. The web server provides html and javascript pages to a browser -- also running on your desktop.

您在桌面上运行 Web 服务器。Web 服务器向浏览器提供 html 和 javascript 页面 - 也在您的桌面上运行。

回答by Epeli

回答by sanchez

回答by user492851

I assume you are mobilizing a web-application for cross platform access.

我假设您正在为跨平台访问移动 Web 应用程序。

If so have you considered abstracting the cross platform access at the web-app presentation layer ?

如果是这样,您是否考虑过在 Web 应用程序表示层抽象跨平台访问?

Appcelerator / Webkit does not provide true native look-and-feel on mobile devices but this is where a new technology can help.

Appcelerator / Webkit 不能在移动设备上提供真正的原生观感,但这是一项新技术可以提供帮助的地方。

回答by li.davidm

If you're after webkit bindings for Python, look at PyQt, which includes Webkit, as well as wxWebkit (http://wxwebkit.wxcommunity.com/) if you're using wxWidgets. This lets you embed webkit in a Qt or Wxwidgets app so that you won't have to go through a browser.

如果您正在寻找 Python 的 webkit 绑定,请查看 PyQt,其中包括 Webkit,以及 wxWebkit ( http://wxwebkit.wxcommunity.com/)(如果您使用 wxWidgets)。这让您可以在 Qt 或 Wxwidgets 应用程序中嵌入 webkit,这样您就不必通过浏览器。

If you do use this, then you can either use a web server in Python, like others have mentioned, or you can control the Webkit control directly (though I'm not sure how practical this is).

如果您确实使用它,那么您可以使用 Python 中的 Web 服务器,就像其他人提到的那样,或者您可以直接控制 Webkit 控件(尽管我不确定这有多实用)。

Beyond that, there's also Pyjamas Desktop (http://pyjs.org/), which lets you use Pyjamas to build the application, then run it.

除此之外,还有 Pajamas Desktop ( http://pyjs.org/),它允许您使用 Pajamas 构建应用程序,然后运行它。

回答by Toni Ru?a

Hereis a nice PyCon talk on the subject.

是关于这个主题的一个很好的 PyCon 演讲。

回答by Riklaunim

If you are thinking about real desktop applications that are multi-threaded and/or use multiple system component - forget about JavaScript. That requires a very good SDK (like PyQt4), and not a basic wrapper like Appcelerator Titanium. Note that developing such applications takes a lot of time.

如果您正在考虑多线程和/或使用多个系统组件的真实桌面应用程序 - 忘记 JavaScript。这需要一个非常好的 SDK(比如 PyQt4),而不是像 Appcelerator Titanium 这样的基本包装器。请注意,开发此类应用程序需要花费大量时间。

Second option is to drop the desktop binding and make a web application with an advanced frontend UI made with one of JavaScript frameworks & friends (Ember, Angular... up to things like dhtmlx and alike widgets). Those can't use system components (like access some hardware), but they can provide nice services.

第二种选择是删除桌面绑定,并使用 JavaScript 框架和朋友(Ember、Angular ......直到 dhtmlx 和类似小部件)之一制作的具有高级前端 UI 的 Web 应用程序。那些不能使用系统组件(如访问某些硬件),但它们可以提供很好的服务。

回答by Pake Beet

PHP Desktop is an open source project founded by Czarek Tomczak in 2012 to provide a way for developing native desktop GUI applications using web technologies such as PHP, HTML5, JavaScript & SQLite. The development workflow you are used to while creating web applications remains the same. The step of turning an existing website into a desktop application is basically a matter of copying it to the "www/" directory.

PHP Desktop 是一个开源项目,由 Czarek Tomczak 于 2012 年创立,旨在提供一种使用 PHP、HTML5、JavaScript 和 SQLite 等 Web 技术开发原生桌面 GUI 应用程序的方法。您在创建 Web 应用程序时习惯的开发工作流程保持不变。将现有网站转变为桌面应用程序的步骤基本上是将其复制到“www/”目录。

PHP Desktop also releases Python Desktop and Ruby Desktop. It allows you to create a Windows app, that either uses the installed IE for the front-end, or uses an instance of Chrome (so definitely HTML5 support too) that is packaged with the app. It starts a local webserver, supports many databases with a PDO driver and you can layout the views in HTML and Javascript. You can download external resources like any other website/webapp, so it supports network related stuff too. The app ships with its own bare-bones version of Python, you can add libraries as desired.

PHP Desktop 还发布了 Python Desktop 和 Ruby Desktop。它允许您创建一个 Windows 应用程序,该应用程序使用已安装的 IE 作为前端,或者使用与应用程序一起打包的 Chrome 实例(当然也支持 HTML5)。它启动一个本地网络服务器,支持许多带有 PDO 驱动程序的数据库,您可以用 HTML 和 Javascript 布局视图。您可以像任何其他网站/网络应用程序一样下载外部资源,因此它也支持网络相关的内容。该应用程序自带 Python 的基本版本,您可以根据需要添加库。

I looked at all the answers before, as I had the exact same question as you, but PHP Desktop easily solved it for me.

我之前看了所有的答案,因为我和你有完全相同的问题,但是 PHP Desktop 很容易为我解决了。

https://code.google.com/p/phpdesktop/wiki/EmbeddingOtherScriptingLanguages

https://code.google.com/p/phpdesktop/wiki/EmbeddingOtherScriptingLanguages

回答by user3801836

Take a look at pySide

看看pySide

I suggest using QtWebKit

我建议使用QtWebKit

And you can use PyInstallerif you want to hide the source code.

如果你想隐藏源代码,你可以使用PyInstaller

回答by PythonProgrammer

You can use TideSDK that can help you creating beautiful and unique desktop apps using your web development skills (HTML5 / CSS3 / JavaScript / Python or PHP or Ruby).

您可以使用 TideSDK,它可以帮助您使用您的 Web 开发技能(HTML5/CSS3/JavaScript/Python 或 PHP 或 Ruby)创建漂亮且独特的桌面应用程序。

Website: http://www.tidesdk.org

网站:http: //www.tidesdk.org

Using Python in TideSDK: http://tidesdk.multipart.net/docs/user-dev/generated/#!/guide/using_python

在 TideSDK 中使用 Python:http://tidesdk.multipart.net/docs/user-dev/generated/#!/guide/using_python

Hope that helps! :)

希望有帮助!:)