Remove the selected items : ListBox « Tkinker « Python Tutorial






Remove the selected items
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()








18.19.ListBox
18.19.1.Add item to ListBoxAdd item to ListBox
18.19.2.ListBox with scroll barListBox with scroll bar
18.19.3.Creating a multiple selection list.Creating a multiple selection list.
18.19.4.Add item to the end of ListBoxAdd item to the end of ListBox
18.19.5.Remove the selected itemsRemove the selected items
18.19.6.Scrolled listScrolled list