diff --git a/async_tkinter_loop/mixins.py b/async_tkinter_loop/mixins.py new file mode 100644 index 0000000..cabea16 --- /dev/null +++ b/async_tkinter_loop/mixins.py @@ -0,0 +1,24 @@ +import sys +import tkinter + +from async_tkinter_loop import async_mainloop + + +class AsyncTk: + def mainloop(self: tkinter.Tk): + async_mainloop(self) + + +class AsyncCTk(AsyncTk): + def mainloop(self): + if not self._window_exists: + if sys.platform.startswith("win"): + self._windows_set_titlebar_color(self._get_appearance_mode()) + + if not self._withdraw_called_before_window_exists and not self._iconify_called_before_window_exists: + # print("window dont exists -> deiconify in mainloop") + self.deiconify() + + self._window_exists = True + + super().mainloop() diff --git a/examples/custom_tkinter.py b/examples/custom_tkinter.py new file mode 100644 index 0000000..7e4ef27 --- /dev/null +++ b/examples/custom_tkinter.py @@ -0,0 +1,32 @@ +import asyncio + +import customtkinter + +from async_tkinter_loop import async_handler +from async_tkinter_loop.mixins import AsyncCTk + + +class App(AsyncCTk, customtkinter.CTk): + def __init__(self): + super().__init__() + self.geometry("600x500") + self.title("Async CTk example") + + # add widgets to app + self.button = customtkinter.CTkButton(self, command=self.button_click) + self.button.grid(row=0, column=0, padx=20, pady=10) + + self.label = customtkinter.CTkLabel(self, text="") + self.label.grid(row=0, column=1, padx=20, pady=10) + + @async_handler + async def button_click(self): + i = 0 + while True: + i += 1 + self.label.configure(text=str(i)) + await asyncio.sleep(1.0) + + +app = App() +app.mainloop() diff --git a/poetry.lock b/poetry.lock index 9c4a4dc..31fc439 100644 --- a/poetry.lock +++ b/poetry.lock @@ -170,6 +170,34 @@ tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.1 [package.extras] toml = ["tomli"] +[[package]] +name = "customtkinter" +version = "5.2.0" +description = "Create modern looking GUIs with Python" +optional = true +python-versions = ">=3.7" +files = [ + {file = "customtkinter-5.2.0-py3-none-any.whl", hash = "sha256:f8b2db189959033539884d7faff99ebbb654c18097d761ed844180e32f0b5929"}, + {file = "customtkinter-5.2.0.tar.gz", hash = "sha256:e93448a8d22121e20ec16e95960a8306e17cf7e0079766f5804b2e855e614937"}, +] + +[package.dependencies] +darkdetect = "*" + +[[package]] +name = "darkdetect" +version = "0.8.0" +description = "Detect OS Dark Mode from Python" +optional = true +python-versions = ">=3.6" +files = [ + {file = "darkdetect-0.8.0-py3-none-any.whl", hash = "sha256:a7509ccf517eaad92b31c214f593dbcf138ea8a43b2935406bbd565e15527a85"}, + {file = "darkdetect-0.8.0.tar.gz", hash = "sha256:b5428e1170263eb5dea44c25dc3895edd75e6f52300986353cd63533fe7df8b1"}, +] + +[package.extras] +macos-listener = ["pyobjc-framework-Cocoa"] + [[package]] name = "exceptiongroup" version = "1.1.3" @@ -557,9 +585,9 @@ files = [ ] [extras] -examples = ["Pillow", "httpx"] +examples = ["Pillow", "customtkinter", "httpx"] [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "c5edf309588851ce09170e48390c7e0854f8add001447f1eba0fcbe105329c8f" +content-hash = "7947c61df06aedf2b948a680300acdcdeb897e2560cba03e9997fb83dea03489" diff --git a/pyproject.toml b/pyproject.toml index c8156b7..21fce7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ classifiers = [ python = "^3.8.1" Pillow = {version = "^9.1.1", optional = true} httpx = {version = ">=0.23.1,<0.25.0", optional = true} +customtkinter = {version = "^5.2.0", optional = true} [tool.poetry.group.dev.dependencies] pytest = "^7.4.0" @@ -30,7 +31,7 @@ black = "^23.3.0" isort = "^5.11.5" [tool.poetry.extras] -examples = ["httpx", "Pillow"] +examples = ["httpx", "Pillow", "customtkinter"] [build-system] requires = ["poetry-core>=1.0.0"]