The Wayback Machine - https://web.archive.org/web/20240118175713/https://www.geeksforgeeks.org/how-to-remove-multiple-selected-items-in-listbox-in-tkinter/
Open In App
Related Articles

How to remove multiple selected items in listbox in Tkinter?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Prerequisite: Tkinter, Listbox in Tkinter

Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications.

In this article, we will learn how to remove multiple selected checkboxes in Listbox Using Tkinter in Python.

Let’s Understand step by step implementation:-

1. Create Normal Tkinter Window

Python3




from tkinter import *
  
root = Tk()
root.geometry("200x200")
  
root.mainloop()


Output:

2. Add Listbox using Listbox() method

Syntax: 

Listbox(root, bg, fg, bd, height, width, font, ..) 

Python3




# Import Module
from tkinter import *
  
# Create Object
root = Tk()
  
# Set Geometry
root.geometry("200x200")
  
# Add Listbox
listbox = Listbox(root, selectmode=MULTIPLE)
listbox.pack()
  
# Listbox Items List
items = ["Apple", "Orange", "Grapes", "Banana", "Mango"]
  
# Iterate Through Items list 
for item in items:
    listbox.insert(END, item)
  
Button(root, text="delete").pack()
  
# Execute Tkinter
root.mainloop()


Output:

3. Remove Selected Item From Listbox

  • Get a List of selected Items from Listbox using the curselection() method.
  • Iterate through all list and remove item using delete() method

Below is the implementation:-

Python3




# Import Module
from tkinter import *
  
# Function will remove selected Listbox items
def remove_item():
    selected_checkboxs = listbox.curselection()
  
    for selected_checkbox in selected_checkboxs[::-1]:
        listbox.delete(selected_checkbox)
  
# Create Object
root = Tk()
  
# Set Geometry
root.geometry("200x200")
  
# Add Listbox
listbox = Listbox(root, selectmode=MULTIPLE)
listbox.pack()
  
# Listbox Items List
items = ["Apple", "Orange", "Grapes", "Banana", "Mango"]
  
# Iterate Through Items list 
for item in items:
    listbox.insert(END, item)
  
Button(root, text="delete", command=remove_item).pack()
  
# Execute Tkinter
root.mainloop()


Output:


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 02 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials