Execution#
tk_execute#
- tk_async_execute.utils.tk_execute(method: Callable, *args, **kwargs)#
Allows thread-safe execution of tkinter methods.
- Parameters:
method (Callable) – A tkinter widget method. Methods that are not from tkinter widgets, should be called directly without this function.
args (Any) – Positional arguments to pass to
methodkwargs (Any) – Keyword arguments to pass to
method
async_execute#
- tk_async_execute.utils.async_execute(coro: ~typing.Coroutine, wait: bool = True, visible: bool = True, pop_up: bool = False, callback: ~typing.Callable | None = None, show_exceptions: bool = True, message: str | ~typing.Callable[[str], str] | None = <function <lambda>>, show_stdout: bool = True, **kwargs)#
Executes a coroutine inside asyncio event loop.
Call this from tkinter callbacks.
- Parameters:
coro (Coroutine) – The coro to run.
wait (Optional[bool]) –
Wait until the execution of
corohas completed, before returning from this function. Defaults to True.WARNING If multiple executions are happening at once, due to the way tkinter’s event loop works, this will wait for all executions to finish before returning from this function in the LIFO manner (last execution will be exited first).
visible (Optional[bool]) – Show the execution progress through a new window. Defaults to True.
pop_up (Optional[bool]) – If True, all other windows will be blocked from interactions, until the execution of
corois complete. Defaults to False.callback (Optional[Callable]) – Callback function to call with result afer coro has finished. Defaults to None.
show_exception (Optional[bool]) – If True, any exceptions that ocurred in
corowill be display though a message box on screen. If you want to obtain the exception though code, you can do so by setting parameterwaitof this function to True and then callingwindow.future.exception().message (Optional[str | Callable[[str], str]]) – Message to be displayed in the window, when
visibleparameter is set to True. When a string (str) is provided, it will be displayed as the message. If a callable is provided, it will be called with the function name as a parameter, and it must return a string that will be used as the displayed message.show_stdout (Optional[bool]) – If True, any write to stdout (e.g., the
print()function) will be displayed in the window when the execution window is shown (visible=True). Defaults to True.**kwargs – Any tkinter specific parameters to the TopLevel widget.
- Returns:
The progress TopLevel window responsible for
coroexecution.- Return type:
- Raises:
Exception – Exception that occurred in
coro(if it ocurred). Only raised ifwaitis True.