I'm creating a window in which you have 4 options in a checkbutton (using Tkinter in Python). I wish that, whenever you click one option, the others change state do DISABLED. I saw a post in which they used this:
root = Tk()
def click():
check.config(state=DISABLED)
check = Checkbutton(text="Click Me", command=click)
check.grid()
root.mainloop()
However, in my program I have several windows, and I am located in the third window. And when I make a def to make the unselected checkbuttons to disable i get an error that says that my checkbuttons are not defined, this is the part of the code that matters:
budget1 = IntVar()
budget2 = IntVar()
budget3 = IntVar()
budget4 = IntVar()
window3 = Toplevel()
window3.config(bg="lightgreen")
window3.title("My details")
window3.resizable(1, 1)
secondary_font=("Arial 20 bold")
check_3box = Frame(window3, bg="lightgreen")
check_3box.grid(column=0, row=7)
W9_W3 = Checkbutton(check_3box, text="$0-$300", variable=budget1, bg="white", fg="black", command=budget_disable(1))
W9_W3.grid(column=0,row=7, padx=15, pady=1)
W10_W3 = Checkbutton(check_3box, text="$300-500", variable=budget2, bg="white", fg="black", command=budget_disable(2))
W10_W3.grid(column=1, row=7, padx=15, pady=1)
W11_W3 = Checkbutton(check_3box, text="$500-$900", variable=budget3, bg="white", fg="black", command=budget_disable(3))
W11_W3.grid(column=2, row=7, padx=15, pady=1)
W12_W3 = Checkbutton(check_3box, text="$900+",variable=budget4, bg="white", fg="black", command=budget_disable(4))
W12_W3.grid(column=3, row=7, padx=15, pady=1)
And I have this def right at the begining of the code
def budget_disable(a):
if a == 1:
W10_W3.config(state=DISABLED)
W11_W3.config(state=DISABLED)
W12_W3.config(sate=DISABLED)
if a == 2:
W9_W3.config(state=DISABLED)
W11_W3.config(state=DISABLED)
W12_W3.config(sate=DISABLED)
if a == 3:
W9_W3.config(state=DISABLED)
W10_W3.config(state=DISABLED)
W12_W3.config(sate=DISABLED)
if a == 4:
W9_W3.config(state=DISABLED)
W10_W3.config(state=DISABLED)
W11_W3.config(state=DISABLED)
And the error that appears is
NameError: name 'W10_W3' is not defined