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()), y=43, anchor="center")

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

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

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

    self.xscrollbar = ttk.Scrollbar(self.frame, orient='horizontal',
    self.xscrollbar.grid(row=4, column=0, sticky='ew')

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

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

    for index, row in data_list.iterrows():'', 'end', text=index, values=tuple(row.values))["displaycolumns"] = self.ld.getFieldlist()[:5]"<Double-1>", self.OnDoubleClick)

    return self.frame

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?


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.