from tkinter import *
root = Tk()
listbox = Listbox(root)
listbox.insert(END,'ListBox1')
listbox.insert(END,'ListBox2')
listbox.insert(END,'ListBox3')
listbox.pack()
root.mainloop()
多选
listbox = Listbox(root, selectmode = MULTIPLE)
listbox = Listbox(root, selectmode = BROWSE)
listbox = Listbox(root, selectmode = EXTENDED)
#追加item
listbox.insert(0,"addBox1","addBox2")
#删除item
listbox.delete(3,4)
#删除全部(0,END)
#选中
listbox.select_set(0,2)
#取消选中
listbox.select_clear(0,1)
#返回制定索引的项值
print(listbox.get(1))
#返回多个项值,返回元组
print(listbox.get(0,2))
#返回当前选中项的索引
print(listbox.curselection())
#判断是否选中
print(listbox.select_includes(0))
print(listbox.select_includes(2))
def printList(event):
print(listbox.get(listbox.curselection()))
#双击
listbox.bind('' , printList)
v = StringVar()
listbox = Listbox(root, listvariable=v)
v.set(('SetValue','SetValue2','SetVaule3'))