Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions async_tkinter_loop/async_tkinter_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ async def main_loop(root: tk.Tk) -> None:
code.

Args:
----
root: tkinter root window object

"""
while True:
# Process all pending events
Expand All @@ -35,10 +33,8 @@ def get_event_loop() -> asyncio.AbstractEventLoop:
"""
A helper function which returns an event loop using current event loop policy.

Returns
-------
Returns:
event loop

"""
return asyncio.get_event_loop_policy().get_event_loop()

Expand All @@ -48,29 +44,29 @@ def async_mainloop(root: tk.Tk) -> None:
A function, which is a substitute to the standard `root.mainloop()`.

Args:
----
root: tkinter root object

"""
get_event_loop().run_until_complete(main_loop(root))


P = ParamSpec("P")


def async_handler(async_function: Callable[P, Coroutine[Any, Any, None]], *args, **kwargs) -> Callable[P, None]:
def async_handler(
async_function: Callable[P, Coroutine[Any, Any, None]],
*args: Any, # noqa: ANN401
**kwargs: Any, # noqa: ANN401
) -> Callable[P, None]:
"""
A helper function which allows to use async functions as command handlers (e.g. button click handlers) or event
handlers.

Args:
----
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

Returns:
-------
A sync function, which runs the original async function in an async event loop.

Usage examples:
Expand Down Expand Up @@ -105,7 +101,6 @@ async def some_async_function():

button = tk.Button("Press me", command=some_async_function)
```

"""

@wraps(async_function)
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_tkinter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""A simple example how to use async code with CustomTkinter
"""
"""A simple example how to use async code with CustomTkinter"""

import asyncio

Expand Down