python - 尝试加载 eel.js 时出现找不到文件错误
问题描述
我目前正在使用 eel 在 html/python 中编写一个简单的 GUI。不幸的是,虽然直接从官方教程中复制了它,但当我尝试加载 eel.js 时,我收到错误“GET file:///C:/eel.js net::ERR_FILE_NOT_FOUND”。我的标题看起来像这样:
<head>
<meta charset="utf-8">
<title>My eel GUI</title>
<script type="text/javascript" src="/eel.js"></script>
<script>
eel.expose(my_function)
function my_function(text) {
console.log("Hello!")
}
</script>
</head>
谢谢您的帮助。
我的 python 文件看起来像这样:
import eel
class GUI:
def __init__(self):
eel.init("web")
eel.start("main.html", block = False)
eel.sleep(5)
解决方案
在您的init函数之上添加 @eel.expose 。像这样的东西:
class GUI:
@eel.expose
def __init__(self):
eel.init("web")
eel.start("main.html", block=False)
eel.sleep(5)
def test_my_function(self):
eel.my_function()
x = GUI()
x.test_my_function()
推荐阅读
- python - 如何在 Numpy 数组中设置单个索引
- c# - Deserialize JSON with empty string key
- java - 基于 HTTP 请求 getLocale 的货币抛出 IllegalArgumentException
- regex - 捕获两个字符之间的子字符串?
- python - Using a conditional comprehesion and the re.search function to find all the strings in a list?
- postgresql - 加密的 AWS PostgreSQL RDS 如何在幕后工作?
- javascript - Why is my iframe blocked by cross origin even it is not
- google-apps-script - GmailApp.Search not returning emails in a date range
- coq - 仅折叠应用程序
- c++ - 为什么在这里使用 int64_t 错误并且 int 编译?