added darkdetect Windows and Linux support

This commit is contained in:
Tom Schimansky 2021-07-13 11:23:34 +02:00
parent 96462ea600
commit 54ede3a548
5 changed files with 24 additions and 27 deletions

View File

@ -1,3 +1,5 @@
__version__ = "1.1"
from .customtkinter_button import CTkButton from .customtkinter_button import CTkButton
from .customtkinter_slider import CTkSlider from .customtkinter_slider import CTkSlider
from .customtkinter_frame import CTkFrame from .customtkinter_frame import CTkFrame

View File

@ -1,12 +1,13 @@
from threading import Thread from threading import Thread
from time import sleep from time import sleep
import sys import sys
from distutils.version import StrictVersion as Version
import darkdetect
if sys.platform == "darwin": if Version(darkdetect.__version__) < Version("0.3.1"):
try: sys.stderr.write("WARNING: You have to update the darkdetect library: pip3 install --upgrade darkdetect\n")
import darkdetect if sys.platform != "darwin":
except ImportError as e: exit()
sys.stderr.write(str(e) + "\nERROR: You have to install darkdetect: pip install darkdetect\n")
class SystemAppearanceModeListener(Thread): class SystemAppearanceModeListener(Thread):
@ -35,7 +36,6 @@ class SystemAppearanceModeListener(Thread):
@staticmethod @staticmethod
def detect_appearance_mode(): def detect_appearance_mode():
if sys.platform == "darwin":
try: try:
if darkdetect.theme() == "Dark": if darkdetect.theme() == "Dark":
return 1 # Dark return 1 # Dark
@ -43,8 +43,6 @@ class SystemAppearanceModeListener(Thread):
return 0 # Light return 0 # Light
except NameError: except NameError:
return 0 # Light return 0 # Light
else:
return 0 # Light
def run(self): def run(self):
while True: while True:
@ -72,7 +70,6 @@ class SystemAppearanceModeListenerNoThread():
@staticmethod @staticmethod
def detect_appearance_mode(): def detect_appearance_mode():
if sys.platform == "darwin":
try: try:
if darkdetect.theme() == "Dark": if darkdetect.theme() == "Dark":
return 1 # Dark return 1 # Dark
@ -80,8 +77,6 @@ class SystemAppearanceModeListenerNoThread():
return 0 # Light return 0 # Light
except NameError: except NameError:
return 0 # Light return 0 # Light
else:
return 0 # Light
def update(self): def update(self):
detected_mode = self.detect_appearance_mode() detected_mode = self.detect_appearance_mode()

View File

@ -1,8 +1,8 @@
import tkinter import tkinter
import customtkinter # <- import the CustomTkinter module import customtkinter # <- import the CustomTkinter module
customtkinter.enable_macos_darkmode() #customtkinter.enable_macos_darkmode()
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light" #customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
root_tk = tkinter.Tk() # create the Tk window like you normally do root_tk = tkinter.Tk() # create the Tk window like you normally do
root_tk.geometry("400x240") root_tk.geometry("400x240")

View File

@ -1,9 +1,9 @@
import tkinter import tkinter
import customtkinter # <- import the CustomTkinter module import customtkinter # <- import the CustomTkinter module
from PIL import Image, ImageTk # <- import PIL for the images #from PIL import Image, ImageTk # <- import PIL for the images
customtkinter.enable_macos_darkmode() #customtkinter.enable_macos_darkmode()
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light" #customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
root_tk = tkinter.Tk() # create the Tk window like you normally do root_tk = tkinter.Tk() # create the Tk window like you normally do
root_tk.geometry("400x240") root_tk.geometry("400x240")

View File

@ -10,7 +10,7 @@ def read(filename):
setup(name="customtkinter", setup(name="customtkinter",
version="1.0", version="1.1",
author="Tom Schimansky", author="Tom Schimansky",
license="Creative Commons Zero v1.0 Universal", license="Creative Commons Zero v1.0 Universal",
url="https://github.com/TomSchimansky/CustomTkinter", url="https://github.com/TomSchimansky/CustomTkinter",