[Tutor] Left Alignment -- Tkinter

W W srilyk at gmail.com
Sat Mar 28 21:46:26 CET 2009

On Sat, Mar 28, 2009 at 9:47 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net>wrote:

>  Hi, that's an interesting way to look at it. Actually, I was about to
> probe the color idea myself, but needed to better understand how to achieve
> it. Where did grid_columnconfigure(3, weight=1) come from? I don't recall
> seeing that with Frame. Grid has columnconfigure. I started down that path
> once, but got waved off. Interesting about master.

It's not part of frame, it's actually part of the grid manager, but you have
to call it on the parent widget, and as such it won't get screwy when
combined with a parent that has the .pack method called on it.

 http://effbot.org/tkinterbook/grid.htm is a pretty decent reference.

> What I've discovered is that I did not really understand the role of
> sticky, and the bounds of the label. I thought sticky=W  meant put the
> blasted label to the left margin. What sticky means, according to Grayson's
> chapter 5 on the web, is that it allows the widget to stretch when the
> larger window is resized.  Knowing the boundaries with color coding can help
> understand that, and other oddities. Label seems to always center the text.
> Changing the label's width and height achieves interesting insights. I tried
> anchor with Label and it does interesting things. The length of the text
> messes with matters.


The justify option will change the alignment of text in the label.

> To put some focus on what I think is the real problem, try this. See if the
> text in labels lines up on the left if a column of Labels is create with
> these labels.
> vinegar
> pie
> latitude for x
> Snowy
> I haven't tried it yet, but would expect to get something like:
>      vinegar
>         pie
> latitude for x
>     Snowy
> anchor with Label may move them to the left.
> In my case, I'm looking for stuff like:
> Latitude  BOX    Longitude  BOX
> x  BOX  y BOX
> and not
>    Latitude BOX     Longitude BOX
>           x BOX   y BOX

Grid is a useful manager for this type of scenario. Grid is very similar to
the old HTML table. If you want to align it that way with grid, you could
easily do something that looks like this:

| Latitude   | Box    | Longitude  | Box     |
| x | BOX| y | BOX  |                               |

Forgive the poor ascii art, but with some simple configurations like
columnspan, you can set it up to fit whatever you want (it usually helps to
draw out your design on paper).

> I want the text in the left column aligned. It doesn't really matter about
> the alignment of Longitude with y. One would think this would be a snap. I'm
> quite surprised no one seems to have considered an example along these
> lines. I guess everyone is center happy.

Using the grid manager and justify=LEFT you shouldn't have much of a problem

> I have yet to find a good source that explains Grid in a thorough way. Lots
> of piecemeal things. Many too brief. Perhaps the best thing I've found is
> Grayson's chapter 5 image editor, p86f. He has a very complex looking grid
> of buttons, combo boxes and images, but it all makes sense as to the layout.
> It took me awhile to see why he needed so many rows and columns for those 9
> (actually 10) thumbnails. It's all about what goes on in the lower right
> corner. Unfortunately, he had no need to align the text to the left
> uniformly in a column.

If you want to have the text align you have a few options - you can have
several labels in the same grid row/column, or you can line them up with
their own cells.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090328/9acabc7f/attachment-0001.htm>

More information about the Tutor mailing list