आइए मान लें कि हमने टिंकर में लिस्टबॉक्स विधि का उपयोग करके एक सूची बॉक्स बनाया है और हम इस सूची से कई चयनित वस्तुओं को हटाना चाहते हैं।
लिस्टबॉक्स से एकाधिक सूची का चयन करने के लिए, हम selectmode . का उपयोग करेंगे बहु . के रूप में . अब सूची पर पुनरावृति करते हुए, हम कुछ बटनों का उपयोग करके डिलीट ऑपरेशन कर सकते हैं।
उदाहरण
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame or window
win= Tk()
#Set the geometry
win.geometry("700x400")
#Create a text Label
label= Label(win, text="Select items from the list", font= ('Poppins bold', 18))
label.pack(pady= 20)
#Define the function
def delete_item():
selected_item= my_list.curselection()
for item in selected_item[::-1]:
my_list.delete(item)
my_list= Listbox(win, selectmode= MULTIPLE)
my_list.pack()
items=['C++','java','Python','Rust','Ruby','Machine Learning']
#Now iterate over the list
for item in items:
my_list.insert(END,item)
#Create a button to remove the selected items in the list
Button(win, text= "Delete", command= delete_item).pack()
#Keep Running the window
win.mainloop() आउटपुट
उपरोक्त कोड को चलाने से निम्न आउटपुट उत्पन्न होगा -

अब, आप सूची बॉक्स में कई प्रविष्टियों का चयन कर सकते हैं और उन प्रविष्टियों को सूची से हटाने के लिए "हटाएं" बटन पर क्लिक कर सकते हैं।

ध्यान दें, यहां हमने "हटाएं" बटन का उपयोग करके सूची से तीन प्रविष्टियां हटा दी हैं।