Closed FaheemM1020 closed 4 months ago
I have the same problem, as a work around you have to recreate the entire gui. Is a bit odd but do able. I think the build in Theme Manager does not diectly pushes the theme changes to the widgets, instead i think it simply acts as a library with theme parameters and when a widget gets created it asks the the Theme Manager which colours to use. Don't know for sure, but it seems like it is working like this.
Is there any way to fix this ?
If you find it useful, i can provide a bit more help. Have recently created my own EventManager and somewhat learned how it works
Below is rewritten with ChatGPT 😹
To improve the ThemeManager, consider implementing a structure similar to that of an EventManager. This would involve creating a static class, say EventManager
, which maintains a dictionary. This dictionary would map observers to their respective callbacks. When a button event, associated with a theme change, is triggered, the EventManager
would employ a notify
method. This method's purpose is to inform all subscribed observers about the theme change.
As a result, each observer's callback is executed, potentially with optional parameters passed along. To adapt to these theme changes, subscribers—which could be widgets or entire GUI component classes—must either regenerate all widgets or manually adjust their color settings to match the new theme.
For instance, in a Python application using customtkinter, the implementation might look something like this:
class EventManager:
observers = {}
@staticmethod
def subscribe(observer, callback):
EventManager.observers[observer] = callback
@staticmethod
def notify(theme):
for callback in EventManager.observers.values():
callback(theme)
# Example callback function for a theme change
def on_theme_change(new_theme):
# Logic to change the theme of your GUI components
print(f"Theme changed to {new_theme}")
# Subscribing to the theme change event
EventManager.subscribe("myWidget", on_theme_change)
# Simulating a theme change event
EventManager.notify("Dark Mode")
In this example, the EventManager
class is used to manage theme change events. Widgets or GUI components subscribe to these events by registering a callback function with the EventManager
. When the theme changes, the EventManager
notifies all subscribed components by calling their registered callbacks with the new theme, allowing each component to update its appearance accordingly.
Do you mean chaning the color of all widgets individually ??
Since the internal ThemeManager doesn't support dynamic color theme changes, you have three options: 1) Inform the user that an application restart is necessary to apply the new theme, 2) Implement your own ThemeManager using an event system that notifies various parts of your GUI about the change, prompting widget recreation, or 3) Use the same event system to manually update all visual aspects, such as colors, without recreating widgets.
Ok Thanks
How do i change the default color theme by clicking in a button i tried this but it didnt work or didnt gave any error