Eremiso
Eremiso

Reputation: 11

Showing pandas Dataframe in Treeview Tkinter and changing width of first column

This is my code. As you can see bellow I am trying to display small data in Treeview. But I don't know how can i change the width of the first column without a name that represents index in pandas dataframe. Also showing in img how it looks in app.

import pandas as pd
from tkinter import *
from tkinter import ttk

df = pd.read_csv("Employees_data", index_col=0)

root = Tk()
root. geometry("760x450")

tree1 = ttk.Treeview(root)
tree1.pack()
tree1['columns'] = df.columns.values.tolist()

for i in df.columns.values.tolist():
    tree1.column(i, width=50)
    tree1.heading(i, text=i)
for index, row in df.iterrows():
    tree1.insert("", 'end', text=index, values=list(row))
print(df.iterrows())

root.mainloop()
      Name  work hours     specialization
1    Zosia          12  Pracownik biurowy
2   Maciek           7  Pracownik biurowy
3   Jakcek          10         Sprzątanie
4  Ryszard          10         Magazynier
5  Mateusz          14         Magazynier

enter image description here

Upvotes: 1

Views: 1208

Answers (1)

Paul
Paul

Reputation: 11

Try access to first column via name '#0'. This works for me:

tree.column('#0', width = 80, anchor="w")

Upvotes: 1

Related Questions