Library API
async_handler(async_function, *args, **kwargs)
A helper function which allows to use async functions as command handlers (e.g. button click handlers) or event handlers.
async_function: async function
args: positional parameters which will be passed to the async function
kwargs: keyword parameters which will be passed to the async function
A sync function, which runs the original async function in an async event loop.
Usage examples:
import tkinter as tk
from async_tkinter_loop import async_handler
async def some_async_function():
print("Wait...")
await asyncio.sleep(0.5)
print("Done!")
button = tk.Button("Press me", command=async_handler(some_async_function))
# ----
async def some_async_function(event):
print("Wait...")
await asyncio.sleep(0.5)
print("Done!")
root.bind("<1>", command=async_handler(some_async_function))
# ----
# Also, it can be used as a decorator
@async_handler
async def some_async_function():
print("Wait...")
await asyncio.sleep(0.5)
print("Done!")
button = tk.Button("Press me", command=some_async_function)
Source code in async_tkinter_loop/async_tkinter_loop.py
async_mainloop(root)
A function, which is a substitute to the standard root.mainloop()
.
root: tkinter root object
get_event_loop()
A helper function which returns an event loop using current event loop policy.
Returns
event loop
Source code in async_tkinter_loop/async_tkinter_loop.py
main_loop(root)
async
An asynchronous implementation of tkinter mainloop. The function is not intended to be called directly from your code.
root: tkinter root window object