Welcome folks today in this blog post we will be clearing
out all elements which are present inside listbox widget inside tkinter in python. All the full source code of the application is given below.
In order to get started you need to make an
app.py file and copy paste the following code
# -*- 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()
Now if you execute the
python script by typing the below command