使用Tkinter获取在列表框中选择的多个项目并使用值填充新列表 [英] get multiple items chosen in a listbox and populate new list with the values, using Tkinter
本文介绍了使用Tkinter获取在列表框中选择的多个项目并使用值填充新列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从列表框中进行选择,并用它填充一个新列表,它将是多个项目.我无法弄清楚,这是到目前为止的内容(我需要列表中的实际字符串,而不是索引).另外,选择后如何完全摆脱Tkinter小部件-它已关闭,但关闭后似乎仍然有鬼影.
I am trying to take the selection from a listbox and populate a new list with it, and it will be multiple items. I can't figure this out, here's what i have so far (and I need the actual strings in the list, not the indices). Also, how can I completely get rid of the Tkinter widgets after making the selection - it closes out but it seems like there is a ghost of it still hanging around after it closes.
def execute(*events):
UsrFCList = []
selctd_indices = lbox.curselection()
lst_select = list(selctd_indices)
for i in lst_select:
lbox.get(i)
UsrFCList.append(i)
lbox.quit()
fc_lb = Tk()
scrollbar = Scrollbar(fc_lb)
scrollbar.pack(side=RIGHT, fill=Y)
lbox = AutoSzLB(fc_lb,selectmode=EXTENDED)
for item in lb_list:
lbox.insert(END, *item)
button = Button(fc_lb, text="Analyze selected feature classes", command=execute)
lbox.autowidth(250)
lbox.pack()
button.pack()
lbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=lbox.yview)
mainloop()
推荐答案
我知道了,而不是
for i in lst_select:
lbox.get(i)
UsrFCList.append(i)
是
for i in lst_select:
UsrFCList.append(lbox.get(i))
这篇关于使用Tkinter获取在列表框中选择的多个项目并使用值填充新列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文