How to clear a listbox when a button is clicked to re-populate it? The code below is giving me an error.
code:
self.listNodes.delete(0,END)
error:
NameError: name 'END' is not defined
Clear ListBox With the DataSource = null Approach in C# The best solution for this would be to specify the ListBox. DataSource property equal to null to remove the data source and then use the ListBox. Items. Clear() function to clear the previous items in the list box.
Use the selectmode parameter on the Listbox widget. You can click the selected item again and it will clear the selection.
The default is 20. If you want to allow the user to scroll the listbox horizontally, you can link your listbox widget to a horizontal scrollbar.
Introduction to the Tkinter Listbox A Listbox allows you to browse through the items and select one or multiple items at once. To create a listbox, you use the tk.Listbox class like this: listbox = tk.Listbox(container, listvariable, height) In this syntax: The container is the parent component of the listbox.
Depending on how you imported tkinter you may have to put end in quotations Try:
self.listNodes.delete(0,'end')
you can also use:
self.listNodes.delete(0,tk.END)
Replace:
self.listNodes.delete(0,END)
with:
self.listNodes.delete('0','end')
END
is a variable of tkinter module, which suggests either a wildcard(from tkinter import *
) import or from tkinter import END
was supposed to be used.
You can use this is you imported tkinter as:
import tkinter as tk
self.listnodes.delete(0, tk.END)
Or you can do:
from tkinter import *
self.listnodes.delete(0, END)
Destruction is the best way to delete something.
self.listNode.destroy()
and then add Your data again to your ListBox
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With