Tkinter Treeview has an index column too wide, and it cannot be resized

Question:

I’ve been working on a Tkinter app for a while, and a part of it is a Treeview widget that displays data. I managed to mash up some code I found because I have almost zero experience with Treeview, and it put together a functioning Treeview, with one catch; the index column (the first column) is far too big, takes up space which could be used for columns that need it, and most importantly, it cannot be resized, like the other columns can.

cols = list(rawdata.columns)

tree.grid_remove()
tree = ttk.Treeview(frame_datapreview, height=40)
tree.grid(row=0, column=0)
tree["columns"] = cols
for i in cols:
    tree.column(i, anchor="w", stretch=NO, width=50)
    tree.heading(i, text=i, anchor='w')

for index, row in rawdata.iterrows():
    tree.insert("", index, text=index, values=list(row))

Here’s what the output looks like:

enter image description here

Is there any way to resize the index column? Or, if there isn’t, is there a way to get rid of the index column alltogether?

Asked By: cocobolodesk

||

Answers:

You can use the special id "#0" to configure the tree column.

tree.column("#0", width=100)
Answered By: Bryan Oakley
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.