尝试加载时获取文件未找到错误 eel.js

Getting file not found error when trying to load eel.js

我目前正在 html/python 使用 eel 编写一个简单的 GUI。不幸的是,虽然直接从官方教程中复制了它,但在尝试加载 eel.js 时出现错误 "GET file:///C:/eel.js net::ERR_FILE_NOT_FOUND"。我的 header 看起来像这样:

<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()