0

I am trying to make a GUI in which contains combobox and checkbutton. I want the checkbutton to be disabled (gey out) when a specific combobox option is selected.

Following is my code: ( Here I am trying to disable the checkbox1 if the combobox value is 0)

import Tkinter as tk
import ttk

root=tk.Tk()
combo=ttk.Combobox(root,values=['0','1','2'])
combo.set("Select No")
combo.place(relx=0.01,rely=0.4)

var1=IntVar()
check1=tk.Checkbutton(root,text="Select1", variable=var1)
check1.place(relx=0.01,rely=0.6)

var2=IntVar()
check2=tk.Checkbutton(root,text="Select2", variable=var2)
check2.place(relx=0.4,rely=0.6)

if combo.get()=='0':
    check1.config(state=tk.DISABLED)

root.mainloop()

1 Answer 1

1

You can use the ComboboxSelected event bind as follows:

def disable(event):
    if combo.get()=='0':
        check1.config(state = tk.DISABLED)
combo.bind("<<ComboboxSelected>>", disable)

The callback function disable is invoked each time the value of the Combobox is changed

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it worked. I just had to add else condition to make the checkbutton normal.
Could you have a look at another problem I am having at stackoverflow.com/questions/58063559/…

Your Answer

By clicking “Post Your Answer”, 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.