tristan957
tristan957

Reputation: 571

Tkinter Treeview, only the first value in a list being displayed

Here is my code for inserting:

import tkinter as tk
from tkinter import ttk

class SummaryTree(ttk.Treeview):
    def __init__(self, parent, kwargs):
        ttk.Treeview.__init__(self, parent, columns=2, selectmode=tk.NONE, show='tree', takefocus=False)

        self.column('#1', anchor=tk.W)
        self.tag_configure('evenrow', background='#cecece')

        for index, item in enumerate(kwargs.items()):
            if index % 2 == 0:
                self.insert('', tk.END, text=item[0], values=item[1], tags=('evenrow',))
            else:
                self.insert('', tk.END, text=item[0], values=item[1])

if __name__ == '__main__':
    root = tk.Tk()
    kwargs = {
        'Soda': [
            'Sprite',
            'Mountain Dew',
            'Coke'
        ],
        'Numbers': [
            5,
            6,
            7
        ]
    }
    SummaryTree(root, kwargs).pack()
    root.mainloop()

For some reason this code is only inserting the first value in the lists. I'm not quite sure what I am missing here.

Upvotes: 1

Views: 1171

Answers (1)

Josselin
Josselin

Reputation: 2643

According to the ttk.Treeview documentation, the columns option is:

A list of column identifiers, specifying the number of columns and their names

So if you want your Treeview to have 3 columns named 1, 2, and 3, you should write:

ttk.Treeview.__init__(self, parent, columns=[1, 2, 3], ...)

Upvotes: 2

Related Questions