String alignment in Tkinter

Viewed 4226

I want a message box in Python which shows the concatenated string text. I want the text is left aligned but it doesn't. I tried ljust() and {:<14} etc. But it still not aligned.

It seems like this:

enter image description here

The code piece is below,

for todo_item in resp.json()['SectorList']:
    sector_id +='Sector Id: {:<14}'.format(todo_item['SectorId']) + '\n'
    sector_name += 'Sector Name: {:<40}'.format(todo_item['SectorName']) + '\n'

After the loop I add those texts into my message box.

label_id = tkinter.Label(f, anchor = tkinter.W, text = sector_id)
label_name= tkinter.Label(f,anchor = tkinter.W, text = sector_name)

label_id.grid(row= 2, column = 1, sticky = tkinter.W)
label_name.grid(row= 2, column = 2, sticky = tkinter.W)

Sector id part is fine but sector name is not left aligned. Any idea?

3 Answers
Related