How to disable Combobox in Tkinter?

Basically, I want to disable a specific Combobox based on the value of another combobox. I could not find the answer to this question, perhaps because it is very rarely possible to do this with Combobox.

I have the code more or less as follows ...

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" 

Thanks in advance

CHANGE !!!!

After saving, I found the answer, and it is quite simple. For those who may be interested, a solution can be found here: http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_combobox.htm

"state = 'disabled', 'readonly' or 'normal'"

+7
python tkinter combobox
source share
1 answer

You want to use the Combobox state='disabled' parameter.

There are three options for state :

  • state='normal' , which is a fully functional Combobox .
  • state='readonly' , which is a Combobox with a value but cannot be changed (directly).
  • state='disabled' , where Combobox cannot interact with.
+3
source share

All Articles