[英]How to disable a Combobox in Tkinter?
基本上,我想基於另一個組合框的值禁用某個組合框。 我找不到這個問題的答案,也許是因為對組合框執行此操作非常罕見。
我有一個或多或少的代碼如下...
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"
提前致謝
編輯!!!!
堅持之后,找到了答案,這很簡單。 對於那些可能感興趣的人,可以在這里找到解決方案: http : //www.tcl.tk/man/tcl8.5/TkCmd/ttk_combobox.htm
“狀態=“已禁用”,“只讀”或“正常”
您想使用state='disabled'
的Combobox
選項。
state
三個選項如下:
state='normal'
是功能齊全的Combobox
。 state='readonly'
,它是帶有值的組合Combobox
,但不能(直接)更改。 state='disabled'
,無法與組合Combobox
進行交互。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.