Python on Electron framework(电子框架上的 Python)
问题描述
我正在尝试使用 Web 技术(HTML5、CSS 和 JS)编写一个跨平台的桌面应用程序.我看了一些框架并决定使用 Electron 框架.
I am trying to write a cross-platform desktop app using web technologies (HTML5, CSS, and JS). I took a look at some frameworks and decided to use the Electron framework.
我已经用 Python 完成了应用程序,所以我想知道是否可以在 Electron 框架上使用 Python 编写跨平台桌面应用程序?
I've already done the app in Python, so I want to know if is possible to write cross-platform desktop applications using Python on the Electron framework?
推荐答案
可以使用 Electron,但如果您正在寻找webbish" UI 功能,您可以查看 Flexx - 它允许您使用纯 Python 编写代码,但仍然使用 Web 开发工具的样式和 UI 灵活性.
It is possible to work with Electron but if you are looking for "webbish" UI capabilities, you can check Flexx - it allows you to code in pure Python but still use the styling and UI flexibility of web development tools.
如果你坚持使用 Electron,你应该遵循这个 发帖.
If you insist on going on Electron you should follow the idea of this post.
首先确保你已经安装了所有东西:
First make sure you have everything installed:
pip install Flask
npm install electron-prebuilt -
npm install request-promise -g
现在创建您希望所有魔法发生的目录并包含以下文件
Now create the directory where you want all the magic to happen and include following files
创建你的 hello.py:
from __future__ import print_function
import time
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! This is powered by Python backend."
if __name__ == "__main__":
print('oh hello')
#time.sleep(5)
app.run(host='127.0.0.1', port=5000)
创建你的基本 package.json:
{
"name" : "your-app",
"version" : "0.1.0",
"main" : "main.js",
"dependencies": {
"request-promise": "*",
"electron-prebuilt": "*"
}
}
最后创建你的 main.js:
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
electron.crashReporter.start();
var mainWindow = null;
app.on('window-all-closed', function() {
//if (process.platform != 'darwin') {
app.quit();
/
本文标题为:电子框架上的 Python
基础教程推荐
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
