【发布时间】:2021-01-21 08:11:23
【问题描述】:
为了从我的列表框中删除项目,我使用了一个循环,但它只删除了第一个选定的项目。我不能使用Listbox.delete(i,j,k),因为我不能将我的元组“索引”作为 Listbox.delete() 的参数传递。
需要帮助。
def App():
root=Tk()
operatorList=tk.Listbox(root,selectmode="MULTIPLE")
operatorList.pack()
#binding the Listbox
conn = sqlite3.connect('C:/Users/Stagiaire/Desktop/Ketrika/VCbase.db')
cursor=conn.cursor()
cursor.execute("SELECT operatorId,operatorName from Operator")
OpRecord=cursor.fetchall()
conn.close()
i=0
for operator in OpRecord:
operatorList.insert(i,operator)
i=i+1
workingOperator=[]
def CmdSelect():
index=operatorList.curselection()
for i in index:
o=operatorList.get(i)
workingOperator.append(o)
operatorList.delete(i)
SelectButton=Button(root,text="Select",command=SelectCmd)
SelectButton.pack()
root.mainloop()
【问题讨论】: