40

My program uses a ttk.Treeview as a table and fills it with many numbers.

I want to clear the ttk.Treeview when I press a button in the window.

Is there a simple way to clear the ttk.Treeview?

Thanks.

Moshe
  • 9,283
  • 4
  • 29
  • 38
katze
  • 1,273
  • 3
  • 16
  • 24

4 Answers4

119

Even simpler:

tree.delete(*tree.get_children())
James Adam
  • 2,324
  • 3
  • 16
  • 19
23

Ok, I found. I post the answer if someone need an answer to my question :

for i in tree.get_children():
    tree.delete(i)
katze
  • 1,273
  • 3
  • 16
  • 24
0

Following on from Katze's answer, after you delete the tree you might need to update the window to reflect the changes

for i in tree.get_children():
   tree.delete(i)
window.update()

You'd have to keep your program in a while true loop instead of a mainloop

while True:
  if condition_check():
      for i in tree.get_children():
         tree.delete(i)
      window.update()
Daniel
  • 45
  • 1
  • 9
0

Let row be a single data from the Treeview called Table

for row in Table.get_children():
   Table.delete(row)
Abbilaash
  • 1
  • 3