python-eel/Eel

Can't use JS function in Python

Open

#499 建立於 2021年6月13日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Python (570 fork)batch import
help wanted

倉庫指標

Star
 (5,980 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

I use eel in my own project and try to call JS function in python but not work.

so I try to use the example1 hello world , and It looks like still not call back to js but show no error. DO I missing to install or do something? I just import eel and start it .

import eel

eel.init('web')                     # Give folder containing web files

@eel.expose                         # Expose this function to Javascript
def say_hello_py():
    
    eel.say_hello_js('World!')

say_hello_py()
   # Call a Javascript function

eel.start('main.html')             # Start (this blocks and enters loop)
...
<html>
       <head>
        <title>Hello, World!</title>
        
        <!-- Include eel.js - note this file doesn't exist in the 'web' directory -->
        <script type="text/javascript" src="/eel.js"></script>
        <script type="text/javascript">
        
        eel.expose(say_hello_js);               // Expose this function to Python
        function say_hello_js(x) {
            console.log("Hello from " + x);
        }
        
        say_hello_js("Javascript World!");
        eel.say_hello_py();  // Call a Python function
        
        </script>
    </head>
    
    <body>
        Hello, World!
    </body>
</html>

Desktop (please complete the following information):

  • OS: Win10
  • Browser : chrome

貢獻者指南