Reputation: 570
I am trying to get a label to be center justified between a given width, but it's not working. What am I doing wrong?
from tkinter import *
from tkinter.ttk import *
def main():
root = Tk()
root.geometry("200x100")
root.minsize(0,0)
root.resizable(0,0)
a = Label(master=root, text="Hello World", justify="center", background="red")
a.pack()
a.place(x=0,y=0, width=120)
mainloop()
main()
Upvotes: 1
Views: 1293
Reputation: 385870
The text is properly justified in the label. The problem is that you didn't tell the label to stretch to fill the window. To do that, pack it like this:
a.pack(fill="x")
Also, it serves no purpose to call pack and then immediately call place -- only the last one will have any effect. Plus, you should avoid using place unless you have no other choice. Place is fine, but it makes your program harder to maintain, and harder to get it to grow and shrink.
Upvotes: 2