pythontkinternestedduplicatestreeview

Treeview table showing duplicates from list of lists


For a program that takes information from the network I would like to display it in a table to make selections (calculate average, stdev ect.). I created a list of lists and I am trying to populate it into a treeview table. The table should show serial number, the parameters requested and their respected values. The populating works, but I get 3 duplicates of every row and the final row per serialnumber shows 7 duplicates (while my list of lists only shows 1 result per line).

I've been struggling for some time to remove the duplicates and checked the suggestions here. Behind the '#' in the code below are the suggestions I found. Behind the '->' I mention the result.

def displayInfo():
    #tree.delete(*tree.get_children()) -> Shows no improvement at all
    for results in fullResults:
        # tree.delete(0, "end")  -> doesn't run as it doesn't recognise command
        # tree.delete(*tree.get_children())  -> Shows no improvement at all
        for result in results:
            # tree.delete(*tree.get_children()) -> deletes the previous serialnumber
            for value in result:
                tree.insert('', 'end', values=result)

Can you please point me to some direction?


Solution

  • I think that you should not use the loop " for value in result" because you are inserting "values= result" in the last command i.e. "tree.insert". Using for in loop, you are iterating over all the elements in iterable i.e. result. But you are inserting in the treeview- the value that the variable "result" holds. So it means by using the loop you are inserting in the treeview table-n number of times-the value that the variable "result" stores . Here, 'n' is the length of iterable "result".