anon
anon

Reputation:

"Justify=LEFT" NOT WORKING on Tkinter Label Widget

So, I have tkinter labels and I want the text within them to be left aligned. I am using justify=LEFT but it isn't working. I can't figure out why?

This is the code for my Label Widget:

Label(displayWindow, text=value, width=15, borderwidth=3, justify=LEFT, relief=GROOVE, font=("times",13,"bold"), bg="lightblue").grid(row=row_num+1,column=col, padx=5, sticky=EW)

This is the output: enter image description here

NOTE: How the contents in column First Name and Last Name are not LEFT aligned they are still CENTER aligned.

Upvotes: 2

Views: 10611

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

The justify option only comes into play when the text wraps to multiple lines. You need to use the anchor option if you want the text to be at the left edge of the widget.

Label(..., anchor="w")

From the canonical tcl/tk man page:

anchor - Specifies how the information in a widget (e.g. text or a bitmap) is to be displayed in the widget. Must be one of the values n, ne, e, se, s, sw, w, nw, or center. For example, nw means display the information such that its top-left corner is at the top-left corner of the widget.

justify - When there are multiple lines of text displayed in a widget, this option determines how the lines line up with each other. Must be one of left, center, or right. Left means that the lines' left edges all line up, center means that the lines' centers are aligned, and right means that the lines' right edges line up.

Upvotes: 6

Related Questions