Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support of CustomTkinter using mixins #51

Merged
merged 1 commit into from
Aug 21, 2023
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
24 changes: 24 additions & 0 deletions async_tkinter_loop/mixins.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions examples/custom_tkinter.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 30 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
Loading