tkinter puzzler

Paul Rubin http
Thu May 12 03:16:22 EDT 2005


I have a gui with a bunch of buttons, labels, the usual stuff.  It
uses the grid manager:

   gui = Frame()
   gui.grid()
   gui.Label(....).grid()  # put some widgets into the gui
   ...    # more widgets

Now at the the very bottom of the gui, I want to add two more buttons,
let's say "stop" and "go".  I want "stop" to appear in the gui's lower
left corner and "go" to appear in the gui's lower right corner.
Suppose that up to now, row 16 is the last row in the gui.  Then this
works:

    Button(gui, text="stop").grid(sticky=W)   # starts row 17
    Button(gui, text="go").grid(row=17, column=1, sticky=E)

But I don't really want that hardwired row number and I don't want to
keep counting rows and adjusting stuff if I stick new rows in the gui.
So I try the obvious, make one Frame widget containing both new buttons:
    stopgo = Frame(gui)
    Button(stopgo, "stop").grid(sticky=W)
    Button(stopgo, "go").grid(sticky=E)

and try to stretch it across the bottom row of the gui:

    stopgo.grid(sticky=E+W)

However, the buttons keep coming out centered in the gui's bottom row
pretty much no matter what I do (I've tried all sorts of combinations).

Am I missing something?  I'm not a tkinter whiz and this stuff is
pretty confusing.  I did come up with an ugly workaround that I'll
spare you the agony of seeing, but there should be a natural way to do
this.

Thanks for any advice.



More information about the Python-list mailing list