[Tutor] Tkinter: justify label
jfouhy@paradise.net.nz
jfouhy at paradise.net.nz
Wed Jul 20 01:00:23 CEST 2005
Quoting Bernard Lebel <3dbernard at gmail.com>:
> Can you specify a justification for a label widget? I'm reading there
> is a justify option available on this page:
> http://www.pythonware.com/library/tkinter/introduction/x611-text-formatting.htm
> Although I don't know if this option works for label.
It does; it just doesn't do what you think it does :-)
justify is for multi-line labels. If you are looking to position the text
within the label, you need to use anchor.
eg:
>>> from Tkinter import *
>>> tk = Tk()
>>> l1 = Label(tk, text='this is left\njustified', justify=LEFT)
>>> l1.pack()
>>> l2 = Label(tk, text='this, otoh, is right\njustified', justify=RIGHT)
>>> l2.pack()
>>> l3 = Label(tk, text='left aligned', anchor=W)
>>> l3.pack(fill=X)
>>> l4 = Label(tk, text='right aligned', anchor=E)
>>> l4.pack(fill=X)
--
John.
More information about the Tutor
mailing list