Python Forum
[Tkinter] Clearing listboxes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Clearing listboxes
#1
I currently use this function to clear multiple listboxes, but i feel is not a good way to do it and am sure can be done with a for loop but can't work it out.
def delete_result():  # used in refreshing the data
    runner1.delete(0, tk.END)
    fw1.delete(0, tk.END)
    fp1.delete(0, tk.END)
    vw1.delete(0, tk.END)
I will be adding many more listboxes so need a better option.
Reply
#2
Not tested but, might could put them in a list. Something like
my_listboxes = ['runner1', 'fw1', 'fp1', 'vw1']
for listbox in my_listboxes:
    listbox.delete(0, tk.END)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
cheers, looks like that works, i did something similar but i zip them together, must have been where i went wrong.
Reply
#4
You can use winfo_children() if you want to clear all the list boxes. This does entry widgets too.
for child in frame.winfo_children():
    if isinstance(child, (tk.Entry, tk.Listbox):
        child.delete(0, tk.END)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Clearing Text in Tkinter icabero0225 2 25,999 May-31-2017, 09:38 PM
Last Post: icabero0225

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020