简体   繁体   English

鳗鱼 python: Javascript 错误鳗鱼不是 function

[英]Eel python: Javascript error eel is not a function

I am using eel to communicate with python.我正在使用 eel 与 python 进行通信。 I'm working in dir C:\Users\Desktop\Eel where I have app.py and inside the UI folder I have index.html, myjava.js, style.css, images but nothing called eel.js .我在目录C:\Users\Desktop\Eel工作,其中我有app.py ,在UI文件夹中我有index.html, myjava.js, style.css, images eel.js I said this because in docs it says to include script called /eel.js .我这么说是因为在文档中它说要包含名为/eel.js的脚本。


index.html索引.html

<head>
    <script type="text/javascript" language="JavaScript" src="./myjava.js"></script>
    <script type="text/javascript" src="/eel.js"></script>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container" onclick="runeel()">
</body>

my Javascript is:我的 Javascript 是:

function runeel(){
    eel.runpy()
}

app.py应用程序.py

import eel

eel.init('UI')
eel.start('index.html', size=(900, 550))

@eel.expose
def runpy():
     ....code which creates an excel file in desktop...

When I run the py file, the index.html loads up and then when I click the div I get into the function and but it throws the error:当我运行 py 文件时, index.html 会加载,然后当我单击 div 时,我会进入 function ,但它会引发错误:

myjava.js:2 Uncaught TypeError: eel.runpy is not a function

What am I missing?我错过了什么?

It seems that the init statement is written first.好像是先写了init语句。 What about writing the @eel.expose statement right after the import statement?在 import 语句之后写 @eel.expose 语句怎么样?

I'm not good at English, so I'm worried that it will make sense.我不擅长英语,所以我担心它会有意义。 But I would be happy if I could help.但如果我能提供帮助,我会很高兴。

i had the same problem until I removed the /eel.js from在我从 /eel.js 中删除之前,我遇到了同样的问题

<script type="text/javascript" src="/eel.js"></script>

now it's look like现在看起来像

<script type="text/javascript" src="eel.js"></script>

In my case, I had to start eel after exposing the function via the decorator:在我的情况下,我必须在通过装饰器暴露 function开始eel

import eel

eel.init('UI')

@eel.expose
def runpy():
     ....code which creates an excel file in desktop...

eel.start('index.html', size=(900, 550))

Try this:尝试这个:

import eel

eel.init('UI')
eel.start('index.html', size=(900, 550))

@eel.expose()
def runpy():
     ....code which creates an excel file in desktop...

What did I change?我改变了什么? i Added () to @eel.expose我将 () 添加到 @eel.expose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM