added CTk class which overrides tkinter.Tk for automatic background color changes

This commit is contained in:
Tom Schimansky
2021-12-31 19:07:53 +01:00
parent afc177ddbb
commit 063c1f8b6a
10 changed files with 84 additions and 40 deletions

View File

@ -6,22 +6,14 @@ import sys
customtkinter.set_appearance_mode("System") # Other: "Light", "Dark"
class App(tkinter.Tk):
class App(customtkinter.CTk):
APP_NAME = "CustomTkinter complex example"
WIDTH = 700
HEIGHT = 500
def __init__(self, *args, **kwargs):
customtkinter.enable_macos_darkmode()
tkinter.Tk.__init__(self, *args, **kwargs)
# color the background of the Tk window if mode is not System
if customtkinter.get_appearance_mode() == "Dark":
self.configure(bg="#323232") # set window background to dark color
elif customtkinter.get_appearance_mode() == "Light":
self.configure(bg="#ECECEC") # set window background to dark color
super().__init__(*args, **kwargs)
self.title(App.APP_NAME)
self.geometry(str(App.WIDTH) + "x" + str(App.HEIGHT))
@ -164,7 +156,6 @@ class App(tkinter.Tk):
print("Button pressed")
def on_closing(self, event=0):
customtkinter.disable_macos_darkmode()
self.destroy()
def start(self):