简体   繁体   中英

Eel python: Javascript error eel is not a function

I am using eel to communicate with 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 . I said this because in docs it says to include script called /eel.js .


index.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:

function runeel(){
    eel.runpy()
}

app.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:

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

What am I missing?

It seems that the init statement is written first. What about writing the @eel.expose statement right after the import statement?

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

<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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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