Eel 基于python+浏览器的开发类似electron 应用
Eel 是基于基于python 可以方便开发基于浏览器的桌面应用,内部eel 可以通过@eel.expose 实现js 与python 代码的互通信
包含的特点
- 使用简单
- 支持js 与python 代码的互相调用
- 支持回掉以及同步处理,当然还支持python 的异步处理
- 提供了基于pyinstaller 的快速打包(支持文件夹以及单文件模式)
- 内部基于bottle web 框架
简单示例
- 项目结构
eel 推荐web 以及python 代码会不同的位置,同时对于web 有一个独立的文件夹
├── app.py
└── webapp
└── main.html
- app.py
import eel
@eel.expose
def say_hello_py(str):
print(f"Hello from python {str}")
eel.init('webapp')
eel.start('main.html',mode="chrome", size=(300, 200))
- webapp/main.html
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
<!-- Include eel.js - note this file doesn't exist in the 'web' directory -->
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript">
eel.expose(say_hello_js); // Expose this function to Python
function say_hello_js(x) {
console.log("Hello from " + x);
}
say_hello_js("Javascript World!");
eel.say_hello_py("python World!"); // Call a Python function
function newwin(){
window.open("https://www.baidu.com", "_blank");
}
</script>
</head>
<body>
Hello, World!
<input type="button" onclick="eel.say_hello_py('button!')" value="Click me!" />
<input type="button" onclick="newwin()" value="new win!" />
</body>
</html>
- 运行效果
- 打包
注意需要安装pyinstaller
python -m eel app.py webapp
效果
说明
基于eel进行桌面开发也是一个不错的选择,值得尝试下
参考资料
https://github.com/python-eel/Eel
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
2024-02-23 dremio cloner 简单试用
2023-02-23 基于tmpfs 的nginx cache 优化
2022-02-23 基于golang cgi 实现一个简单的git http server
2021-02-23 dremio 自定义connector 图标
2021-02-23 dremio sql server 自定义connector开发解决中文乱码问题
2020-02-23 postgres pg_cron 扩展试用
2020-02-23 pgspider pg_cron 以及cstore fdw docker 镜像