Home > Mobile >  Center text in table Python
Center text in table Python

Time:12-29

Here is my code to fetch data from MySQL and present it by a table. But because I am a newbie, I don't really understand about TreeView. Hence I don't know how to center the text in table. (Sorry because of inserting this picture because when I paste the code, it cannot be shown in correct format).

You can find similar lines of code here (in comment section): enter image description here

Here is my table generated: (The text is on the left side of columns). enter image description here

Thank all of you so much!

CodePudding user response:

You need to set anchor for the column of Treeview:

for col in columns:
    listBox.heading(col,text=col,anchor='center')
    listBox.column(col,anchor='center')

Don't name your Treeview as listBox, there is another widget called Listbox too.

Read more about treeview: 45. ttk.Treeview

  • Related