# Eel
[![PyPI version](https://img.shields.io/pypi/v/Eel?style=for-the-badge)](https://pypi.org/project/Eel/)
[![PyPi Downloads](https://img.shields.io/pypi/dm/Eel?style=for-the-badge)](https://pypistats.org/packages/eel)
![Python](https://img.shields.io/pypi/pyversions/Eel?style=for-the-badge)
[![License](https://img.shields.io/pypi/l/Eel.svg?style=for-the-badge)](https://pypi.org/project/Eel/)
Eel is a little Python library for making simple Electron-like offline HTML/JS GUI apps, with full access to Python capabilities and libraries.
> **Eel hosts a local webserver, then lets you annotate functions in Python so that they can be called from Javascript, and vice versa.**
Eel is designed to take the hassle out of writing short and simple GUI applications. If you are familiar with Python and web development, probably just jump to [this example](https://github.com/ChrisKnott/Eel/tree/master/examples/04%20-%20file_access) which picks random file names out of the given folder (something that is impossible from a browser).
<p align="center"><img src="https://raw.githubusercontent.com/samuelhwilliams/Eel/master/examples/04%20-%20file_access/Screenshot.png" ></p>
<!-- TOC -->
- [Eel](#eel)
- [Intro](#intro)
- [Install](#install)
- [Usage](#usage)
- [Directory Structure](#directory-structure)
- [Starting the app](#starting-the-app)
- [App options](#app-options)
- [Chrome/Chromium flags](#chromechromium-flags)
- [Exposing functions](#exposing-functions)
- [Eello, World!](#eello-world)
- [Return values](#return-values)
- [Callbacks](#callbacks)
- [Synchronous returns](#synchronous-returns)
- [Asynchronous Python](#asynchronous-python)
- [Building distributable binary with PyInstaller](#building-distributable-binary-with-pyinstaller)
- [Microsoft Edge](#microsoft-edge)
<!-- /TOC -->
## Intro
There are several options for making GUI apps in Python, but if you want to use HTML/JS (in order to use jQueryUI or Bootstrap, for example) then you generally have to write a lot of boilerplate code to communicate from the Client (Javascript) side to the Server (Python) side.
The closest Python equivalent to Electron (to my knowledge) is [cefpython](https://github.com/cztomczak/cefpython). It is a bit heavy weight for what I wanted.
Eel is not as fully-fledged as Electron or cefpython - it is probably not suitable for making full blown applications like Atom - but it is very suitable for making the GUI equivalent of little utility scripts that you use internally in your team.
For some reason many of the best-in-class number crunching and maths libraries are in Python (Tensorflow, Numpy, Scipy etc) but many of the best visualization libraries are in Javascript (D3, THREE.js etc). Hopefully Eel makes it easy to combine these into simple utility apps for assisting your development.
Join Eel's users and maintainers on [Discord](https://discord.com/invite/3nqXPFX), if you like.
## Install
Install from pypi with `pip`:
```shell
pip install eel
```
To include support for HTML templating, currently using [Jinja2](https://pypi.org/project/Jinja2/#description):
```shell
pip install eel[jinja2]
```
## Usage
### Directory Structure
An Eel application will be split into a frontend consisting of various web-technology files (.html, .js, .css) and a backend consisting of various Python scripts.
All the frontend files should be put in a single directory (they can be further divided into folders inside this if necessary).
```
my_python_script.py <-- Python scripts
other_python_module.py
static_web_folder/ <-- Web folder
main_page.html
css/
style.css
img/
logo.png
```
### Starting the app
Suppose you put all the frontend files in a directory called `web`, including your start page `main.html`, then the app is started like this;
```python
import eel
eel.init('web')
eel.start('main.html')
```
This will start a webserver on the default settings (http://localhost:8000) and open a browser to http://localhost:8000/main.html.
If Chrome or Chromium is installed then by default it will open in that in App Mode (with the `--app` cmdline flag), regardless of what the OS's default browser is set to (it is possible to override this behaviour).
### App options
Additional options can be passed to `eel.start()` as keyword arguments.
Some of the options include the mode the app is in (e.g. 'chrome'), the port the app runs on, the host name of the app, and adding additional command line flags.
As of Eel v0.12.0, the following options are available to `start()`:
- **mode**, a string specifying what browser to use (e.g. `'chrome'`, `'electron'`, `'edge'`, `'custom'`). Can also be `None` or `False` to not open a window. *Default: `'chrome'`*
- **host**, a string specifying what hostname to use for the Bottle server. *Default: `'localhost'`)*
- **port**, an int specifying what port to use for the Bottle server. Use `0` for port to be picked automatically. *Default: `8000`*.
- **block**, a bool saying whether or not the call to `start()` should block the calling thread. *Default: `True`*
- **jinja_templates**, a string specifying a folder to use for Jinja2 templates, e.g. `my_templates`. *Default: `None`*
- **cmdline_args**, a list of strings to pass to the command to start the browser. For example, we might add extra flags for Chrome; ```eel.start('main.html', mode='chrome-app', port=8080, cmdline_args=['--start-fullscreen', '--browser-startup-dialog'])```. *Default: `[]`*
- **size**, a tuple of ints specifying the (width, height) of the main window in pixels *Default: `None`*
- **position**, a tuple of ints specifying the (left, top) of the main window in pixels *Default: `None`*
- **geometry**, a dictionary specifying the size and position for all windows. The keys should be the relative path of the page, and the values should be a dictionary of the form `{'size': (200, 100), 'position': (300, 50)}`. *Default: {}*
- **close_callback**, a lambda or function that is called when a websocket to a window closes (i.e. when the user closes the window). It should take two arguments; a string which is the relative path of the page that just closed, and a list of other websockets that are still open. *Default: `None`*
- **app**, an instance of Bottle which will be used rather than creating a fresh one. This can be used to install middleware on the instance before starting eel, e.g. for session management, authentication, etc. If your `app` is not a Bottle instance, you will need to call `eel.register_eel_routes(app)` on your custom app instance.
- **shutdown_delay**, timer configurable for Eel's shutdown detection mechanism, whereby when any websocket closes, it waits `shutdown_delay` seconds, and then checks if there are now any websocket connections. If not, then Eel closes. In case the user has closed the browser and wants to exit the program. By default, the value of **shutdown_delay** is `1.0` second
### Exposing functions
In addition to the files in the frontend folder, a Javascript library will be served at `/eel.js`. You should include this in any pages:
```html
<script type="text/javascript" src="/eel.js"></script>
```
Including this library creates an `eel` object which can be used to communicate with the Python side.
Any functions in the Python code which are decorated with `@eel.expose` like this...
```python
@eel.expose
def my_python_function(a, b):
print(a, b, a + b)
```
...will appear as methods on the `eel` object on the Javascript side, like this...
```javascript
console.log("Calling Python...");
eel.my_python_function(1, 2); // This calls the Python function that was decorated
```
Similarly, any Javascript functions which are exposed like this...
```javascript
eel.expose(my_javascript_function);
function my_javascript_function(a, b, c, d) {
if (a < b) {
console.log(c * d);
}
}
```
can be called from the Python side like this...
```python
print('Calling Ja
没有合适的资源?快使用搜索试试~ 我知道了~
Eel-main.zip 版本 0.16 内有 examples
共92个文件
py:23个
html:14个
ico:9个
需积分: 1 0 下载量 185 浏览量
2023-09-24
09:53:08
上传
评论
收藏 680KB ZIP 举报
温馨提示
Eel-0.16.0 源代码包 从 https://github.com/python-eel/Eel 下载, Eel 是一个轻量的 Python 库,用于制作简单的类似于 Electron(但是比它更轻量) 的离线 HTML/JS GUI 应用程序,并具有对 Python 函数和库的完全访问权限。 Eel 托管一个本地 Web 服务器,然后允许您使用 Python 注释函数(annotate functions),以便可以从 JavaScript 调用它们,反之亦然。
资源推荐
资源详情
资源评论
收起资源包目录
Eel-main.zip (92个子文件)
Eel-main
eel
__init__.py 16KB
chrome.py 3KB
electron.py 1KB
py.typed 0B
__main__.py 1KB
types.py 919B
eel.js 6KB
edge.py 456B
browsers.py 3KB
.travis.yml 764B
setup.py 1KB
.github
ISSUE_TEMPLATE
feature_request.md 604B
help-me.md 871B
bug_report.md 857B
workflows
test.yml 1KB
codeql-analysis.yml 1KB
main.yml 603B
FUNDING.yml 602B
LICENSE 1KB
.python-version 28B
tests
utils.py 3KB
data
init_test
App.tsx 2KB
sample.html 1KB
hello.html 707B
minified.js 2KB
unit
test_eel.py 1KB
conftest.py 2KB
integration
test_examples.py 3KB
examples
10 - custom_app_routes
web
index.html 81B
custom_app.py 414B
09 - Eelectron-quick-start
main.js 2KB
web
favicon.ico 15KB
hello.html 671B
hello.py 416B
package.json 436B
package-lock.json 27KB
.gitignore 13B
06 - jinja_templates
web
templates
base.html 432B
hello.html 707B
page2.html 130B
favicon.ico 15KB
hello.py 469B
05 - input
web
main.html 1KB
favicon.ico 15KB
script.py 312B
01 - hello_world
web
favicon.ico 15KB
hello.html 671B
hello.py 324B
04 - file_access
web
file_access.html 867B
favicon.ico 15KB
Screenshot.png 14KB
file_access.py 247B
README.md 57B
08 - disable_cache
web
disable_cache.html 369B
favicon.ico 15KB
dont_cache_me.js 87B
disable_cache.py 304B
03 - sync_callbacks
web
sync_callbacks.html 842B
favicon.ico 15KB
sync_callbacks.py 406B
07 - CreateReactApp
src
react-app-env.d.ts 103B
serviceWorker.ts 5KB
index.tsx 451B
App.tsx 2KB
App.test.tsx 248B
logo.svg 3KB
App.css 646B
index.css 380B
package.json 646B
public
manifest.json 306B
favicon.ico 4KB
index.html 2KB
package-lock.json 557KB
Demo.png 522KB
.gitignore 318B
tsconfig.json 494B
README.md 3KB
eel_CRA.py 2KB
01 - hello_world-Edge
hello.py 1KB
02 - callbacks
web
callbacks.html 2KB
favicon.ico 15KB
callbacks.py 774B
CHANGELOG.md 3KB
tox.ini 532B
mypy.ini 624B
requirements-test.txt 161B
requirements.txt 131B
MANIFEST.in 17B
.gitignore 82B
README.md 16KB
requirements-meta.txt 78B
README-developers.md 2KB
共 92 条
- 1
资源评论
belldeep
- 粉丝: 546
- 资源: 50
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功