In the following code, I have been trying to disable the entry1 widget every time I select 1 in the combobox and disable entry2 when i select 2 in combobox.
this is my code:
from Tkinter import *
import ttk
def refresh():
if v.get() == 'A':
entry1.state(['disabled'])
entry2.state(['!disabled'])
elif v.get() == 'B':
entry2.state(['disabled'])
entry1.state(['!disabled'])
root = Tk()
v = StringVar()
var = StringVar()
entry1 = ttk.Entry (root, textvariable= var)
entry1.grid(row=2, column=2, sticky=(E,W))
entry2 = ttk.Entry (root, textvariable= var)
entry2.grid(row=4, column=2, sticky=(E,W))
v_list=['A','B']
v.set(v_list[1])
v_optionmenu = apply(OptionMenu, (root,v) + tuple(v_list))
v_optionmenu.grid(column=4,row=11,sticky=(W,E))
var = v
root.bind('<Return>', lambda e: refresh)
root.mainloop()
I wanted to create condition based enabling and disabling of widgets.
My conditions usually are:
selection in combobox
Selection of radiobutton
Please Advice how i can go about it.
1 Answer