[Tkinter-discuss] Right justify Label against Entry using pack?

John McMonagle jmcmonagle at velseis.com
Thu Dec 2 03:23:40 CET 2010


> I'm experimenting with geometry layouts and would like to know if
> its possible to line up a Label and an Entry widget (in the same
> horizontal line) and have the Label widget right align to the
> Entry widget

Yes, it is possible.

> 
> Here's the 1 line layout I'm trying to achieve:
> 
>      [Label] [Entry        ]
> ^^^
> Where the ^^^ indicates leading space due to right alignment of
> the label against its Entry.
> 



The justify argument in Label is used to apply the appropriate alignment of
the text within the label if that text should span multiple lines.


The following simplification of your code works for me on linux, also
illustrating the use of justify:

rom Tkinter import *
r = Tk()
f = Frame(r)
l = Label(r, text="Password\nHurry up, I'm waiting", width=20, anchor=E,
justify=RIGHT)
l.pack(side=LEFT, fill=X, anchor=E, expand=NO, padx=2)
e = Entry(r)
e.pack(side=LEFT, anchor=W, fill=X, expand=YES)
f.pack(fill=X, expand=YES)
r.mainloop()



More information about the Tkinter-discuss mailing list