1

I'd like to align my text to the left but anchor='w' does not seem to work... Any tips ?

from tkinter import Tk, Label
window = Tk()

lab = Label(window, text = 'hey', anchor='w')
lab2 = Label(window, text='hellooooooo', anchor='w')

lab.grid(column=0, row=0)
lab2.grid(column=0, row=1)
window.mainloop()

tkinter window picture

thomb734
  • 11
  • 2
  • Can you try [this](https://stackoverflow.com/questions/31140590/how-to-line-left-justify-label-and-entry-boxes-in-tkinter-grid)? – Karthick Raju Dec 05 '19 at 11:00

1 Answers1

0

Instead of using anchor property, use sticky property of grid layout. The modified code with sticky will be as follow.

from tkinter import Tk, Label
window = Tk()

lab = Label(window, text = 'hey')
lab2 = Label(window, text='hellooooooo')

lab.grid(column=0, row=0, sticky='w')
lab2.grid(column=0, row=1, sticky='w')
window.mainloop()

Hope this code will do what you want.