[Tutor] Tkinter: justify label

Bernard Lebel 3dbernard at gmail.com
Wed Jul 20 14:28:41 CEST 2005


Awesome, thanks a bunch!

Bernard


On 7/19/05, jfouhy at paradise.net.nz <jfouhy at paradise.net.nz> wrote:
> 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.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list