首页 > 解决方案 > 尝试加载 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)

标签: pythonhtmlpython-3.xeel

解决方案


在您的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()

推荐阅读