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:
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?
You can use the special id "#0"
to configure the tree column.
tree.column("#0", width=100)