How to change a button back to the default color? #2458
Unanswered
RobertCordingly
asked this question in
Q&A
Replies: 1 comment
-
@RobertCordingly, you can utilise class Sample code: from customtkinter import CTk, CTkButton
from customtkinter import ThemeManager
def get_color(class_name: str, property: str = "fg_color") -> tuple[str, str]:
return ThemeManager.theme[class_name][property]
def on_click() -> None:
if button._text != "Confirm":
button.configure(fg_color = get_color("CTkButton"), text="Confirm", hover_color = get_color("CTkButton", "hover_color"))
else:
button.configure(fg_color = "brown", text="Cancel", hover_color="darkred")
if __name__ == "__main__":
app = CTk()
app.geometry("300x200")
button = CTkButton(app, text="Confirm", command=on_click)
button.place(relx=0.5, anchor="center", rely=0.5)
app.mainloop() Hope, this will be helpful. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I want to change a button's color when it's disabled and change it back when it's enabled again, but the obvious way to do this:
self.download_button.configure(fg_color=None)
Doesn't work because the button doesn't check with the ThemeManager when you call configure like it does when the button is initialized.
How can I change the color back to the default?
Beta Was this translation helpful? Give feedback.
All reactions