[Tutor] Left Alignment -- Tkinter

W W srilyk at gmail.com
Sat Mar 28 13:49:12 CET 2009

On Fri, Mar 27, 2009 at 2:46 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net>wrote:

>  It's very difficult to tell. I've tried it.
>         fLocation=Frame(master)
>         fLocation.pack(side=LEFT)
> I need to size the fLocation frame to make it big. As it is, it must be
> giving the smallest possible size.
> I tried this
>         fLocation.pack(expand=YES,fill=BOTH,side=TOP)

Good news... I got it!

Here's something that's often a good idea when debugging overlapping layouts
(especially when you didn't design the parent!) - use different backgrounds!

First I tried grid_rowconfigure and grid_columnconfigure (which are
necessary if you want your widgets in grid to resize and sticky in the
expected places... at least in my experience. You call them on the parent
widget which can be displayed with .pack() ) on fCoords - the parent of your
labels. That didn't do anything, so I suspected the problem went deeper. So
I tried fCoords parent, fLocation. That didn't do anything, so I finally
went to /it's/ parent - master. By setting master.pack(expand=1, fill=BOTH)
along with some other tweaks I was able to get some behavior I think you'll

I've left my background and border changes so you can get a better idea of
what I did. Feel free to play around with the colors, borders, sticky
options, and sizes of things. It'll probably help you to get a better grasp
of what's going on.

Here's my changes (also found here: http://rafb.net/p/clKroD65.html )

# Framing it
from   Tkinter import *
from   tkSimpleDialog import Dialog
import tkSimpleDialog
import tkMessageBox

class DialogPrototype(Dialog):

    def body(self, master):
            # Frames
        master.configure(bg='white', bd=3)
        master.pack(expand=1, fill=BOTH)
        fLocationTitle = Frame(master, bg='green', bd=3)  # fL... f for frame
        fLocation=Frame(master, bg='red', bd=3)
        fLocation.pack(expand=1, fill=BOTH, anchor=W)
        fCoords = Frame(fLocation, bg='blue', bd=3)      # lat/long
coords in a frame
        fCoords.pack(fill=BOTH, expand=1, side=LEFT)
        fCoords.grid_columnconfigure(0, weight=0)
        fCoords.grid_columnconfigure(1, weight=1)
        fCoords.grid_columnconfigure(2, weight=0)
        fCoords.grid_columnconfigure(3, weight=1)
        fCoords.grid_rowconfigure(0, weight=1, minsize=1)

        self.title("Enter Site/Misc. Data")

        # Latitude and Longitude

        Label(fLocationTitle, text="Geographic Location").grid(row=0,column=0)
        #Label(fCoords, text='Latitude:').grid(row=0, sticky=W)
        self.lab=Label(fCoords, text='Latitude:', height=5)
        self.lab.grid(row=0, column=0, sticky=W)
        self.lat = Entry(fCoords, width=12)
        self.lat.grid(row=0, column=1, sticky=W+E)

        Label(fCoords, text='Longitude:').grid(row=0, column=2)
        self.long = Entry(fCoords, width=12)
        self.long.grid(row=0, column=3, sticky=W+E)


    def apply(self):
        print "apply"
        print self.lat.get()
        print self.long.get()

    print "setting"

root = Tk()

The -other- Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090328/5165d995/attachment.htm>

More information about the Tutor mailing list