Python 3 Tkinter Clear or Delete all Elements in ListBox Widget in GUI Desktop App

Python 3 Tkinter Clear or Delete all Elements in ListBox Widget in GUI Desktop App

Python 3 Tkinter Clear or Delete all Elements in ListBox Widget in GUI Desktop App

# -*- coding: utf-8 -*-
import tkinter as tk
 
#clear listbox
def clearListbox():
  lb.delete(0,'end')
 
 
root = tk.Tk()
root.title("Code4Example.com")     # Add a title
 
tk.Button(root,text="Clear Listbox", command=clearListbox).grid(row = 0, column = 0)
 
var2 = tk.StringVar()
var2.set(('Apple','Banana','Pear', 'Peach'))
lb = tk.Listbox(root, listvariable=var2)
lb.grid(row = 0, column = 1)
 
 
root.mainloop()
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment