from Tkinter import *
class ListBoxTest :
def __init__(self) :
self.root = Tk()
self.list_box_1 = Listbox(self.root, selectmode=EXTENDED)
self.list_box_1.pack()
self.delete_button = Button(self.root, text="Delete",command=self.DeleteSelection)
self.delete_button.pack()
for i in range(0, 10) :
s = "Item " + str(i)
self.list_box_1.insert( END,s )
self.root.mainloop()
def DeleteSelection(self) :
items = self.list_box_1.curselection()
pos = 0
for i in items :
idx = int(i) - pos
self.list_box_1.delete( idx,idx )
pos = pos + 1
lbt=ListBoxTest()
|