[Tutor] Left Alignment -- Tkinter

W W srilyk at gmail.com
Mon Mar 30 16:50:45 CEST 2009


On Sun, Mar 29, 2009 at 9:30 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net>wrote:

> <snip>I'm looking at the NM Tech Tkinter ref, pages 5-6, on the grid
> method. See pages 84-88 of Lundh. Nothing. It does not show that method.
> Search of the pdf doc shows nothing. Are these sources too old? effbot does
> have it. Yes, it's pretty decent. I've used it before. It looks like it may
> be the newest, 2005, of the three, although NM Tech seems to get updated
> pretty often. 5/2007, but I think there was a recent update. Maybe they
> don't want the students to use it.
>

I haven't really looked at a lot of tkinter refs. Effbot tends to have most
of the info I need - it just takes a little playing around and sometimes
google or the python list to figure out what part I'm missing.


> <snip>
>> 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.
>>
>
> http://effbot.org/tkinterbook/label.htm
>
> The justify option will change the alignment of text in the label.
>
> It didn't move the text in the label at all. There's got to be some padding
> on either end I'm missing.
>

Actually, it turns out to be my mistake at not clearly reading the
documentation he has for the justify option. Justify is for multiple lines
of text, anchor will anchor the text. Try with width=30, anchor=W and you
should see what you're looking for.


> Interestingly, I had set the width of the label to 12, and the color
> version showed gray to the left and right of the text, with the text in the
> center. I removed width, and the left-right spaces disappeared, but the text
> was still centered. Well, OK, the selected width, which matches the length
> of the text, really doesn't allow for justification. Foiled again. It seems
> like the width for the frame container for the latitude+BOX needs to be
> specified to give latitude some ability to go left. A column for latitude
> and one for BOX?  Beats me. Back to exploration after I finish this
> response. <snip>
>

 It appears you're correct - when I used anchor with padx it was ignored,
but when I changed padx to width it worked as expected. I'm not sure why it
does or doesn't, and I haven't had a lot of time for a lot of experimenting,
and now I have class so I'll just have to leave it for now.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090330/077c0c3c/attachment.htm>


More information about the Tutor mailing list