from __future__ import print_function	# For Py2/3 compatibility
import async_eel
import random
import asyncio


loop = asyncio.get_event_loop()


@async_eel.expose
async def py_random():
    return random.random()


async def print_num(n):
    """callback of js_random"""
    print('Got this from Javascript:', n)


async def main():
    try:
        async_eel.init('web')
        await async_eel.start('callbacks.html', size=(400, 300))

        # Call Javascript function, and pass explicit callback function
        await async_eel.js_random()(print_num)

        # Do the same with an inline callback
        await async_eel.js_random()(lambda n: print('2Got this from Javascript:', n))
    except Exception:
        import traceback
        traceback.print_exc()


if __name__ == '__main__':
    asyncio.run_coroutine_threadsafe(main(), loop)
    loop.run_forever()

[((119, 143), 'asyncio.get_event_loop', 'asyncio.get_event_loop', ([], {}), '()\n', (141, 143), False, 'import asyncio\n'), ((198, 213), 'random.random', 'random.random', ([], {}), '()\n', (211, 213), False, 'import random\n'), ((351, 372), 'async_eel.init', 'async_eel.init', (['"""web"""'], {}), "('web')\n", (365, 372), False, 'import async_eel\n'), ((387, 437), 'async_eel.start', 'async_eel.start', (['"""callbacks.html"""'], {'size': '(400, 300)'}), "('callbacks.html', size=(400, 300))\n", (402, 437), False, 'import async_eel\n'), ((746, 767), 'traceback.print_exc', 'traceback.print_exc', ([], {}), '()\n', (765, 767), False, 'import traceback\n'), ((525, 546), 'async_eel.js_random', 'async_eel.js_random', ([], {}), '()\n', (544, 546), False, 'import async_eel\n'), ((619, 640), 'async_eel.js_random', 'async_eel.js_random', ([], {}), '()\n', (638, 640), False, 'import async_eel\n')]