Tkinter-Async-Execute is a small library, that provides a way to run an asyncio event loop alongside Tkinter in a separate thread.
It provides a way to execute methods of tkinter widgets from inside async functions and ability to call async functions from functions (commands / events) running in tkinter’s thread. The former can be called from any thread (or async function) and the latter only from functions (commands / events) in tkinter’s thread.
To show progress of an async function, submitted from tkinter, an async execution window widget is available, which will display any text printed with the print() function (or any stdout write requests).
Installation
pip install tkinter-async-execute
Documentation
All documentation is available on https://tkinter-async-execute.readthedocs.io/.
Example
from tkinter import ttk
import tkinter as tk
import asyncio
import tk_async_execute as tae
async def async_function():
# Call tkinter widget methods.
print("Disabling button")
tae.tk_execute(bnt.config, state="disabled") # Thread safe exection
await asyncio.sleep(5)
print("Enabling button")
tae.tk_execute(bnt.config, state="normal")
await asyncio.sleep(2)
# Change tkinter text
print("Renaming button")
tae.tk_execute(bnt.config, text="Example 2")
await asyncio.sleep(2)
def button_clicked():
# Call async function
tae.async_execute(async_function(), wait=True, visible=True, pop_up=True, callback=None, master=root)
# Close application
root.quit()
if __name__ == "__main__":
root = tk.Tk()
bnt = ttk.Button(root, text="Click me", command=button_clicked, width=20)
bnt.pack()
tae.start() # Starts the asyncio event loop in a different thread.
root.mainloop() # Main Tkinter loop
tae.stop() # Stops the event loop and closes it.
Metadata
Release files for tkinter-async-execute 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tkinter_async_execute-1.4.0.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tkinter_async_execute-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.1 kB
Release files / tkinter_async_execute-1.4.0.tar.gz
| Download URL | tkinter_async_execute-1.4.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
298fda3f1834e0798e417449d9f5ce27da969b2a90333f58c78f1a7ad3d67bfa
|
|
BLAKE2b-256 checksum How to use checksums |
aa37daba7b6bc2abc1d5141033fd4c725cd7998ec1beca0df1a384f1d5ac72a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.11
|
Release files / tkinter_async_execute-1.4.0-py3-none-any.whl
| Download URL | tkinter_async_execute-1.4.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ab7b65634c797b3b678746b3e8194f8ca7bead224e8322b7721ee7ef057be17
|
|
BLAKE2b-256 checksum How to use checksums |
25061217a1756432d69be62f6bc7995e61a022e7352ccdf1190a5b84a16ad412
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.11
|