如何在Tkinter中禁用Combobox?

Jus*_*ues 9 python combobox tkinter

基本上,我想根据另一个组合框的值禁用某个Combobox.我找不到这个问题的答案,也许是因为这对组合框很常见.

我有一个或多或少的代码如下...

    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')
Run Code Online (Sandbox Code Playgroud)

...

def EnableDisableParamFields(self, event, count):
    if self.cBox1Var.get()=='Combo box':  #disable 'Entry format combo box'
        #disable "self.cBox2"
    else:
        #enable "self.cBox2"
Run Code Online (Sandbox Code Playgroud)

提前致谢

编辑!!!!

坚持下去,找到了答案,这很简单.对于那些可能感兴趣的人,可以在这里找到解决方案:http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_combobox.htm

"state ='禁用','只读'或'正常'"

D'A*_*rcy 6

您要使用的Combobox选项state='disabled'

共有以下三个选项state

  • state='normal'这是功能齐全的Combobox
  • state='readonly'这是Combobox带有值的,但不能(直接)更改。
  • state='disabled'这是Combobox无法与之交互的地方。