Accessing the colours of the current theme manually #228
-
I have some normal Tkinter widgets (tkinter.Text) that I need to make match the current theme of my app. Is there a way to programmatically access the current theme's colors? Something like...
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
ThemeManager is the guy. Hope it helps. import customtkinter
from customtkinter import ThemeManager
_mode = customtkinter.get_appearance_mode()
class Theme:
@staticmethod
def get_color_from_name(name: str, mode = _mode):
return ThemeManager.theme["color"][name][mode]
@staticmethod
def get_property_by_name(prop_name: str):
return ThemeManager.theme[prop_name]
class App(customtkinter.CTk):
def _str_mode_to_int(self, mode : str):
if mode == "Light":
return 0
return 1
def print_colors(self):
print(_mode)
color_names = Theme.get_property_by_name("color")
int_mode = self._str_mode_to_int(_mode)
for color_name in color_names:
print("Current color name is = " , color_name)
print("Value is = ", ThemeManager.theme["color"][color_name][int_mode])
def __init__(self):
super().__init__()
self.title("Sample")
self.geometry("800x600")
bt = customtkinter.CTkButton(self, width=100, height=50, text="Click", command=self.print_colors)
bt.place(anchor="center", relx="0.5", rely="0.5")
App().mainloop() |
Beta Was this translation helpful? Give feedback.
-
Further question: |
Beta Was this translation helpful? Give feedback.
ThemeManager is the guy.
Hope it helps.