Replies: 3 comments 4 replies
-
What about this: PS : The issue is: inside configure method of CTkButton the check for the image variable doesn't have the line Gimme a feedback to let me know if it worked, please |
Beta Was this translation helpful? Give feedback.
-
Yes, you can get the switch value and if the value for the switch I'll post the code tomorrow. |
Beta Was this translation helpful? Give feedback.
-
@Kell90 are you using classes to make the left frame and the right frame? if yes, then you must be placing them in a main window(which would be another file). in order to call the function to the change the button color as per the the theme, you have to follow these steps :
def changeButtonColor(self, mode): #this function takes the current theme mode and changes the image
if mode == "Dark":
self.btn_github.configure(image=self.github_logo_white) #if mode is "Dark", change image to white one
elif mode == "Light":
self.btn_github.configure(image=self.github_logo_black) #if mode is "light", change image to black one
#while you're creating the left frame class you have to take a function argument in the __init__ method which'd be changeButtonColor function, like this
class LeftFrame:
def __init__(self, master, changeImageFunc):
self. button_image_function = lambda theme : changeImageFunc(theme)
self.main_theme = ctk.get_appearance_mode() #this is to save the theme that is currently selected
self.is_dark_mode = True #this is to check if the dark mode is on(im assuming you're using dark mode as default)
from left_frame import LeftFrame
from right_frame import RightFrame
class App:
def __init__(self):
self.main = ctk.CTk()
self.right = RightFrame(self.main)
self.left = LeftFrame(self.main, changeColorFunc=self.right.changeButtonColor) #our left_frame takes the changeButtonColorFunction as an argument in order to run it
self.main.mainloop() Im not very good a explaining, so im leaving the scripts for the reference here. Please do ask if you have any doubts! :D |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As the title suggests, I'd like some button images to change with the theme of the app.
What I have now:


What I want:

Is there a way to programmatically listen for theme changes and swap image accordingly?
Beta Was this translation helpful? Give feedback.
All reactions