Python Forum

Full Version: Python Tkinter treeview showing 6 columns instead of 11 columns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want a tkinter treeview to display the number of columns in a file + the index column. I have 10 columns in a sample file, which means I should expect 11 columns in the table. However, I am only able to show 6 columns including the index column with the following code:

def build_tree(self, data_list, tab_frame):
    self.frame = tab_frame

    variable = StringVar(self.frame)
    w = ttk.OptionMenu(self.frame, variable, *self.ld.getFieldlist())
    w.place(x=105, y=43, anchor="center")

    self.value_txt = ttk.Entry(self.frame, width=25)
    self.value_txt.place(x=285, y=43, anchor="center")

    # treeview
    self.trv = ttk.Treeview(self.frame, selectmode="extended", columns=tuple(data_list.columns.values))

    # treeview's scrollbars
    self.yscrollbar = ttk.Scrollbar(self.frame, orient='vertical', command=self.trv.yview)
    self.trv.configure(yscrollcommand=self.yscrollbar.set)
    self.trv.grid(row=3, column=0, sticky="nsew")
    self.yscrollbar.grid(row=3, column=1, sticky='nse')
    self.yscrollbar.configure(command=self.trv.yview)

    self.xscrollbar = ttk.Scrollbar(self.frame, orient='horizontal', command=self.trv.xview)
    self.trv.configure(xscrollcommand=self.xscrollbar.set)
    self.xscrollbar.grid(row=4, column=0, sticky='ew')
    self.xscrollbar.configure(command=self.trv.xview)

    self.grid_rowconfigure(1, weight=1)
    self.grid_columnconfigure(1, weight=1)

    # treeview's columns (sort columns by calling trv_sort_column)
    self.trv.column('#0', stretch=False, width=90)
    for column in data_list.columns.values:
        self.trv.heading(column, text=column,
                         command=lambda _column=column: trv_sort_column(self.trv, _column, False))
        self.trv.column(column, stretch=False, width=133)

    for index, row in data_list.iterrows():
        self.trv.insert('', 'end', text=index, values=tuple(row.values))

    self.trv["displaycolumns"] = self.ld.getFieldlist()[:5]
    self.trv.bind("<Double-1>", self.OnDoubleClick)

    return self.frame
─░mage


By removing [:5] from the third last line, I am able to get all columns, but some columns get truncated and the scrollbars suddenly disappear. How do I solve this issue?

─░mage


Columns (excluding index column):

ts, UID, Source IP, Source Port, Destination IP, Destination Port, MAC Address, Assigned IP, Lease Time, Trans ID
Please include enough code to be able to run, and provide some sample data.