Python: padding string according to *actual* length
On Windows this code lines up "end" exactly:
import tkinterroot = tkinter.Tk()displaytext1 = "aaa".ljust(10) + "end"displaytext2 = "www".ljust(10) + "end"tkinter.Label(root, text=displaytext1, font = "Courier").pack()tkinter.Label(root, text=displaytext2, font = "Courier").pack()root.mainloop()
Check the value of platform.system() and use other fixed-width fonts depending on the operating system.
I am not going to answer the question you asked, but I will propose a solution to your problem.What you want are several columns.There is a widget for that in tkinter, it is a treeview.
See for example:http://www.tkdocs.com/tutorial/tree.html
I usually recommand the
show='headings'
option in the Treeview constructor when you want a list (and not a tree).