Zasadniczo chcę wyłączyć niektóre Combobox, w oparciu o wartość innego combobox. Nie mogłem znaleźć odpowiedzi na to pytanie, być może dlatego, że bardzo rzadko robi się to w Combobox.Jak wyłączyć Combobox w Tkinter?
Mam kod mniej więcej jak postępować ...
self.cBox1Var=tki.StringVar()
self.cBox1=ttk.Combobox(self.mframe, width=16, textvariable=self.cBox1Var, state='readonly',values=['Text entry','Combo box','Check button'])
self.cBox1.grid(row=0,column=1,sticky=tki.W)
self.cBox1Var.set('Text entry')
self.cBox1Var.bind("<<ComboboxSelected>>", lambda event, count=count: self.EnableDisableParamFields(event, count))
self.cBox2Var=tki.StringVar()
self.cBox2=ttk.Combobox(self.mframe, width=16, textvariable=self.cBox2Var, state='readonly',values=['String','Integer','Float'])
self.cBox2.grid(row=0,column=2,sticky=tki.W)
self.cBox2Var.set('String')
...
def EnableDisableParamFields(self, event, count):
if self.cBox1Var.get()=='Combo box': #disable 'Entry format combo box'
#disable "self.cBox2"
else:
#enable "self.cBox2"
góry dzięki
EDIT !!!!
Po uporaniu się, znalazłem odpowiedź i jest to całkiem proste. Dla tych, którzy mogą być zainteresowani, rozwiązanie można znaleźć tutaj: http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_combobox.htm
„state =«wyłączone»,«tylko do odczytu»lub«normalny»”
BWT: Możesz nawet ukryć widżet - z '.grid_forget()' – furas