How to align text to the left in Tkinter Label?

TkinterServer Side ProgrammingProgramming

Tkinter Label widget can be aligned using the anchor attributes. In order to calculate the accommodate spacing and alignment of the widget, anchor would help in a better way. Anchor provides several options such as N, W, S, E, NW, NE. SW, SE which can be defined in the pack manager itself.


In the following example, we will align the Label text of an application to the left by adding the anchor attribute towards “w” direction.

#Import the required library
from tkinter import*
#Create an instance of tkinter frame
win= Tk()
#Set the geometry
#Create a Label Widget
Label(win, text= "New Line Text", font= ('Helvetica 15 underline'),
background="gray74").pack(pady=20, side= TOP, anchor="w")


Running the above code will align the text label widget towards Left direction.

Updated on 15-Apr-2021 14:02:32