[Tkinter-discuss] pack: difference between anchor and side options? (also anchor as a widget option)

Guilherme Polo ggpolo at gmail.com
Wed Feb 18 04:04:52 CET 2009


On Fri, Feb 13, 2009 at 7:17 PM, John Anon <argo785 at gmail.com> wrote:
> What is the difference between `foo.pack(anchor=...)` and `foo.pack(side=...)`?
>

With "side" you have only four option: top, right, bottom and left,
with "anchor" you can use some combinations of n, w, s, e or use
center (the default). You can also use anchor and side at same time,
for example x.pack(side='top', anchor=''w'). side='top' is the default
one, it defines where in the master the widget will be packed, anchor
defines the position of the widget in this side you chose.

> Actually, regarding `anchor`, I see that you can also use it as an
> option when creating a widget (ex. `Button(parent, anchor=...)` ).
> What's the difference between using it with pack and using as a widget
> option?

For using it with pack see the paragraph above.
Now when you use the option "anchor" while creating a Button, it will
be defining where its text and/or image will be placed in the widget,
just like described above. Try creating a Button with some text, pack
it with expand=True and fill='both' and change the value in anchor to
see how it behaves.

Anyway, by now (4 days late) you probably already found out all this :)

Regards,

-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list