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_slider import CTkSlider
from .customtkinter_frame import CTkFrame

View File

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

View File

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

View File

@ -1,9 +1,9 @@
import tkinter
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.set_appearance_mode("System") # Other: "Dark", "Light"
#customtkinter.enable_macos_darkmode()
#customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
root_tk = tkinter.Tk() # create the Tk window like you normally do
root_tk.geometry("400x240")

View File

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