======================
Tkinter-Async-Execute
======================
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
==============
.. code-block:: bash
pip install tkinter-async-execute
Documentation
=============
All documentation is available on https://tkinter-async-execute.readthedocs.io/.
Example
=============
.. code-block:: python
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.
Raw data
{
"_id": null,
"home_page": "",
"name": "tkinter-async-execute",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Tkinter,asyncio,Async execute,Execution progress window,Thread-safe",
"author": "David Hozic",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/0e/63/b89ff9b1f41d6f5d62dca009f108886d671b7c802344af662b0a7fc228dc/tkinter-async-execute-1.2.0.tar.gz",
"platform": null,
"description": "======================\nTkinter-Async-Execute\n======================\n\nTkinter-Async-Execute is a small library, that provides a way to run an ``asyncio`` event loop alongside Tkinter in\na separate thread.\n\nIt provides a way to execute methods of tkinter widgets from inside async functions and ability to call async functions\nfrom functions (commands / events) running in tkinter's thread. The former can be called from any thread (or async function)\nand the latter only from functions (commands / events) in tkinter's thread.\n\nTo show progress of an async function, submitted from tkinter, an async execution window widget is available,\nwhich will display any text printed with the ``print()`` function (or any stdout write requests).\n\n\nInstallation\n==============\n.. code-block:: bash\n\n pip install tkinter-async-execute\n\nDocumentation\n=============\nAll documentation is available on https://tkinter-async-execute.readthedocs.io/.\n\n\nExample\n=============\n.. code-block:: python\n\n from tkinter import ttk\n import tkinter as tk\n import asyncio\n\n import tk_async_execute as tae\n\n\n async def async_function():\n # Call tkinter widget methods.\n print(\"Disabling button\")\n tae.tk_execute(bnt.config, state=\"disabled\") # Thread safe exection\n await asyncio.sleep(5)\n print(\"Enabling button\")\n tae.tk_execute(bnt.config, state=\"normal\")\n await asyncio.sleep(2)\n\n # Change tkinter text\n print(\"Renaming button\")\n tae.tk_execute(bnt.config, text=\"Example 2\")\n await asyncio.sleep(2)\n\n\n def button_clicked():\n # Call async function\n tae.async_execute(async_function(), wait=True, visible=True, pop_up=True, callback=None, master=root)\n\n # Close application\n root.quit()\n\n\n if __name__ == \"__main__\":\n root = tk.Tk()\n bnt = ttk.Button(root, text=\"Click me\", command=button_clicked, width=20)\n bnt.pack()\n\n tae.start() # Starts the asyncio event loop in a different thread.\n root.mainloop() # Main Tkinter loop\n tae.stop() # Stops the event loop and closes it.\n",
"bugtrack_url": null,
"license": "",
"summary": "Simple library that allows interaction between Tkinter and asyncio event loop running in a seperate thread.",
"version": "1.2.0",
"project_urls": null,
"split_keywords": [
"tkinter",
"asyncio",
"async execute",
"execution progress window",
"thread-safe"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1d34e549ff4ded9affe3ced37935c32ae8947f3d31e3e33889b0066cf3a3c35e",
"md5": "505b9d8746eb6048762644d7fd0a427d",
"sha256": "85a586fbf23de63aaec9a655cfde7c7b853884b7845a43fb941fa8b4208c224f"
},
"downloads": -1,
"filename": "tkinter_async_execute-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "505b9d8746eb6048762644d7fd0a427d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9970,
"upload_time": "2023-09-25T17:51:18",
"upload_time_iso_8601": "2023-09-25T17:51:18.225541Z",
"url": "https://files.pythonhosted.org/packages/1d/34/e549ff4ded9affe3ced37935c32ae8947f3d31e3e33889b0066cf3a3c35e/tkinter_async_execute-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0e63b89ff9b1f41d6f5d62dca009f108886d671b7c802344af662b0a7fc228dc",
"md5": "60d23cb7c9d984dfb5693b37a924bdce",
"sha256": "7e26b5cf2df7bd40afabafd18087bab4e1d32cc7644f1a18eb350154f49ab8c8"
},
"downloads": -1,
"filename": "tkinter-async-execute-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "60d23cb7c9d984dfb5693b37a924bdce",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7837,
"upload_time": "2023-09-25T17:51:19",
"upload_time_iso_8601": "2023-09-25T17:51:19.449293Z",
"url": "https://files.pythonhosted.org/packages/0e/63/b89ff9b1f41d6f5d62dca009f108886d671b7c802344af662b0a7fc228dc/tkinter-async-execute-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-25 17:51:19",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "tkinter-async-execute"
}