我有這樣的名單:元組索引超出相關curselection(Tkinter的)的誤差範圍
lista=Listbox(root,selectmode=MULTIPLE)
lista.grid(column=0,row=1)
lista.config(width=40, height=4)
lista.bind('<<ListboxSelect>>',selecionado)
附此功能:
def selecionado(evt):
global ativo
a=evt.widget
seleção=int(a.curselection()[0])
sel_text=a.get(seleção)
ativo=[a.get(int(i)) for i in a.curselection()]
但是,如果我選擇的東西,然後取消選擇,我得到此錯誤:
seleção=int(a.curselection()[0])
IndexError: tuple index out of rangeenter code here
我該如何防止這種情況發生?
'if len(b)> 0:''可以'如果b:' –
非常感謝保羅 – AllanCampos