Uncategorized

javascript – When using eel, how to call a js function in a python function that was called by js


Python:

import eel
import os
eel.init(os.path.join(os.path.dirname(__file__),"web"))
@eel.expose
def testpy():
    print("testpy called")
    eel.say_hello_js("World")
eel.start('index.html')

Javascript:


function testjs() {
    console.log("testjs called");
    eel.testpy();
}
eel.expose(say_hello_js);
function say_hello_js(x) {
    console.log("Hello" + x);
}

HTML

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
        <title>Test</title>
        <script type="text/javascript" src="./script.js"></script>
        <script type="text/javascript" src="../eel.js"></script>
    </head> 
    <body>  
        <button onclick="testjs()">Test</button>
    </body> 
</html>

The above code runs as expected in that it calls testjs on the click of a button, which calls testpy. But then testpy isnt able to call say_hello_js. I have tried a few things like writing say_hello_js instead of eel.say_hello.js, or exposing all the functions to eel, but I’m not able to get the final function to be called.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *