0

I want to center text in rows. I used tkinter for GUI. Which code should I use and where?

tv1["column"]=list(pivot.columns)
tv1["show"] = "headings"
for column in tv1["columns"]:
    tv1.heading(column, text = column)
    
pivot_rows = pivot.to_numpy().tolist()
for row in pivot_rows:
    tv1.insert("","end", values=row)

GUI

piseynir
  • 237
  • 1
  • 4
  • 14
  • 1
    Take a look [here](https://stackoverflow.com/q/30393763/13382000) – Delrius Euphoria Oct 02 '20 at 20:36
  • i tried this one, it changed column. I want to change the rows position. – piseynir Oct 02 '20 at 20:42
  • Try `tv1.column("#1", anchor="center")` to change the second row, or whatever`cid` you have for the second column. ([source](https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/ttk-Treeview.html)) – Doot Oct 02 '20 at 22:54

1 Answers1

1
tv1["column"] = list(pivot.columns)
tv1["show"] = "headings"
for column in tv1["columns"]:
    tv1.column(column, anchor=CENTER) # This will center text in rows
    tv1.heading(column, text=column)
    
pivot_rows = pivot.to_numpy().tolist()
for row in pivot_rows:
    tv1.insert("","end", values=row)

Found in documentation

geobreze
  • 2,274
  • 1
  • 10
  • 15