0 votes
1 view
in Python by (50.5k points)
I have a python code that is using the eel library to develop a nice GUI.

In the GUI I have a variable within a JS method that I want to pass to Python to store in a variable.

Any ideas why this is?

1 Answer

0 votes
by (108k points)

Please be informed that the Eel package recommends two ways of regaining return values from the other side of the app, which helps keep the code concise.

To stop hanging permanently on the Python side, a timeout has been set in place for attempting to obtain values from the JavaScript side, which defaults to 10000 milliseconds (10 seconds). This can be substituted with the _js_result_timeout argument to eel.init. There is no similar timeout on the JavaScript side.

Say for instance, if we have the following method defined and displayed in 

eel.expose(js_random);

function js_random() {

  return Math.random();

}

#we can retrieve random values from the Javascript side like so:

    def print_num(n):

        print('Got this from ', n)

# Call Javascript function, and pass explicit callback function

eel.js_random()(print_num)

# Do the same with an inline lambda as the callback

eel.js_random()(lambda n: print('Got this from ', n))

(It works exactly the same the other way around).

 Join this Python Training course now if you want to gain more knowledge in Python.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...