I am using following code and trying to center the text on labels:
from tkinter import *
root = Tk()
llist = ["first:","second label:","a really long label:","fourth:","fifth:"]
nrow = 0
for i in range(len(llist)):
# Label(root, text=llist[i], justify='right').grid(row=nrow, column=0) # does not work
# Label(root, text=llist[i], justify=RIGHT).grid(row=nrow, column=0) # does not work
# Label(root, text=llist[i], anchor=E).grid(row=nrow, column=0) # does not work
# Label(root, text=llist[i], anchor=E, justify=RIGHT).grid(row=nrow, column=0) # does not work
Label(root, text=llist[i]).grid(row=nrow, column=0, sticky=E) # WORKS;
Entry(root).grid(row=nrow, column=1)
nrow += 1
root.mainloop()
The text remains in center
with options that I mention as not working in above code:
Only with sticky
option in the grid()
it works properly:
Why justify
and anchor
options of Label
do not work in above code, even though they are mentioned at several places such as http://effbot.org/tkinterbook/label.htm ? How can justify
and anchor
be used to align text in Labels?