tkinter puzzler

Russell E. Owen rowen at cesmail.net
Thu May 12 16:24:24 EDT 2005


In article <7xzmv0hq2h.fsf_-_ at ruckus.brouhaha.com>,
 Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

>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.

A couple of options here:
- Put the main portion of the gui into one frame and pack or grid the 
button frame below that. That sounds like a natural solution to this 
problem based on the way you describe it. (if you do that, I suggest 
packing the buttons into their frame; although I usually use the gridder 
when in doubt, the packer is often the most natural layout manager for a 
row of buttons).

- Increment as you go:
   row = 0

   wdg.grid(row=row, column=0, ...)
   row += 1

   wdg2.grid(row=row, column=0, ...)
   row += 1

- If you are doing a lot of similar layout, it is worth creating a class 
to do your gridding for you. Each instance grids widgets in a particular 
frame. It keeps  track of the row # for you. For use an existing 
gridder, for instance RO.Wdg.Gridder in the RO package 
<http://astro.washington.edu/rowen>.


>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)

This looks OK to me so I'm not sure what's wrong; I think I'd have to 
see your actual code. I suggest examining the size of the stopgo frame 
by setting its background color.

-- Russell



More information about the Python-list mailing list