I have this script in Tk and it works fine. I wanted to make it dark and add hover options, so I changed it to CTk, but now it's not working. Can someone please help me fix this? I have both scripts inhere to show.

(This is part of a bigger script, where it checks multiple buttons to see if it is disabled. If so, show a Label.)

I think there's a problem with this line:

if Button['state'] == DISABLED:

This one works:

from tkinter import *

def ChangeState():
    Button.configure(state="disabled")
    if Button['state'] == DISABLED:
        Button.configure(bg="Green")

window = Tk()

Button = Button(window, text = "Button", command=ChangeState)
Button.pack()

window.mainloop()

This one doens't work:

from customtkinter import *

def ChangeState():
    Button.configure(state="disabled")
    if Button['state'] == DISABLED:
        Button.configure(fg_color="Green")

window = CTk()

Button = CTkButton(window, text = "Button", hover=False, command=ChangeState)
Button.pack()

window.mainloop()

3 Replies 3

What does "not working" mean? Does it use the wrong colors? Does it change the wrong widget? Does it throw an error?

Change Button['state'] to Button.cget('state'). Why don't you just set fg_color="green" in the first Button.configure(...)?

In customtkinter, only cget and configure work because it has custom widgets.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.