How to clear elements from ttk.Treeview widget?

ing_scroll = Scrollbar(window1_frame1, orient=VERTICAL)
ingredients = ttk.Treeview(window1_frame1, yscrollcommand=ing_scroll.set, height=5, columns=['Ingredient', 'Amount'], show="headings")
ingredients.heading("Ingredient", text='Ingredient')
ingredients.column("Ingredient", width=7)
ingredients.heading("Amount", text='Amount')
ingredients.column("Amount", width=1)
ing_scroll.config(command=ingredients.yview)
ing_scroll.pack(side=RIGHT, fill=Y)
ingredients.pack(side=LEFT, fill='both', expand=1)

def OnRecpSelect(event):
    DB = menu_combo.get()
    mytable = recipe_combo.get()
    ingredient_list = TKengine.pull_ingredients(DB, mytable)
    # NEED TO CLEAR THE INGREDIENTS TTK:TREEVIEW OBJECT HERE!
    for i in ingredient_list: 
        ingre = i[1]
        amoun = i[2]
        value = ingre,amoun
        ingredients.insert('',0,values=value)

componentent_list is a list that displays something like ... ('Sugar', '1 Cup'), etc. Def is for a dedicated combobox, so I would like for treeview to clearly and not just add new ingredients. Unfortunately, I do not see the method clear().

If there is a programmatic way to determine what is in the beginning (listing a number of lines would be good ...), it makes me go crazy. I noticed in the docs that you can use the delete method, but it wants to know that the element should delete ... if I use:

ingredients.delete('',0)

I get

TclError: Item 0 not found

So, I would suggest that he wants something like "Sugar" as an item ...

, 22, , combobox , , , ?...

, , - ... treeview, .

+5
2

, insert . , .

, ( ) get_children. get_children, , . .

docs.python.org.

+5

Pythonic:

map(ingredients.delete, ingredients.get_children())
+7

All Articles