Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a Combobox in Tkinter?

Basically, I want to disable a certain Combobox, based on the value of another combobox. I couldn't find a answer to this question, maybe because it's very uncommon to do this to a Combobox.

I have a code more or less as follow...

    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

EDIT!!!!

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

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

like image 980
Justino Rodrigues Avatar asked Jul 07 '14 11:07

Justino Rodrigues


People also ask

How to disable Combobox in Tkinter?

We can Enable or Disable the options in the given Combobox widget by providing the state property. The state property forces to make a widget either active or disabled. To disable the Combobox widget, we have to set the state property as readonly or disabled.

How do you make a combobox not editable in Python?

Combobox is used to create dropdown menus in the Entry Widgets. To create the options, we just simply pass the strings to the values object of combobox. We can disable the combobox by passing the state as “readonly”.

Does tkinter have a combobox?

The Tkinter Combobox is one of the UI widgets in the Tkinter library and it is used for to select the values in the drop-down list column also it is one of the combinations of Entry and drop-down widgets these drop-down entries are replaceable one and the user if suppose not select the value in the box it automatically ...

What is tkinter combobox?

Introduction to the Tkinter Combobox widget A combobox is a combination of an Entry widget and a Listbox widget. A combobox widget allows you to select one value in a set of values. In addition, it allows you to enter a custom value.


1 Answers

You want to use the Combobox option of state='disabled'.

There are three options for state as follows:

  • state='normal' which is the fully functional Combobox.
  • state='readonly' which is the Combobox with a value, but can't be changed (directly).
  • state='disabled' which is where the Combobox cannot be interacted with.
like image 129
D'Arcy Avatar answered Sep 28 '22 03:09

D'Arcy