def save_user(email, password): dict_user = {"email": email, "password": password} # user.insert_one(dict_user).inserted_id user.append(dict_user) print('Calling Javascript...') eel.my_javascript_function(1, 2, 3, 4)(print_num) # This calls the Javascript function # 同步返回 # 在python端, 我们只要不使用回调函数就能同步返回: n = eel.js_random()() # 这里有两个括号 print('Got this from Javascript:', n)
import eel eel.init('web') # Do the same with an inline callback eel.js_random()(lambda n: print('Got this Javascript:', n)) eel.start('main.html', size=(400, 300))
import eel, random eel.init('web') @eel.expose def py_random(): return random.random() def print_num(n): print('Got this from Javascript:', n) # Call Javascript function, and pass explicit callback function eel.js_random()(print_num) # Do the same with an inline callback eel.js_random()(lambda n: print('Got this from Javascript:', n)) eel.start('callbacks.html', size=(400, 300))
import eel import datetime as dt import json import subprocess eel.init('web') @eel.expose def getTime(): now = str(dt.datetime.now()) #return json.dumps({'now':now}) return now #eel.js_random()(print) def testThread(): #below should be replaced by an electron app call if necessary. #maybe have a json file and regular checks from the javascript side to update values. subprocess.call(['touch', 'other.html']) eel.spawn(testThread) eel.start('main.html') random_number_from_javascript = eel.js_random()() print(random_number_from_javascript) eel.say_hello_js('javascript')
import eel, random eel.init('web') @eel.expose def py_random(): return random.random() eel.start('sync_callbacks.html', block=False, size=(400, 300)) # Synchronous calls must happen after start() is called # Get result returned synchronously by # passing nothing in second brackets # v n = eel.js_random()() print('Got this from Javascript:', n) while True: eel.sleep(1.0)
by Erfan Paslar Let's eel https://letscode.erfanpaslar.ir/post.php?pId=16 """ import eel import random eel.init('.//web') ####1#### # if you try to this it will first take some time load and then prints "None" -_- # randomNumberFromJs = eel.js_random()() # print(randomNumberFromJs) # so what you should do is: # and this works fine and we call this called callback function. eel.js_random()(lambda n: print(n)) def printRandom(number): print(number) eel.js_random()(printRandom) #####2##### @ eel.expose def py_random(): return random.randint(0, 100)
from __future__ import print_function import eel import random eel.init('web') @eel.expose def py_random(): return random.random() def print_num(n): print('Got this from Javascript:', n) # Call Javascript function, and pass explicit callback function eel.js_random()(print_num) # Do the same with an inline callback eel.js_random()(lambda n: print('Got this from Javascript:', n)) eel.start('callbacks.html', size=(400, 300))