wxpython wxgrid question

Jim Segrave jes at nl.demon.net
Sun Jun 4 00:02:11 CEST 2006


In article <1149366330.999234.299880 at u72g2000cwu.googlegroups.com>,
 <rbann11 at hotmail.com> wrote:
>Hi,
>
>  I am looking for example code that consists of just a frame and a
>grid(10x2).  The grid must fill the its parent even if the frame is
>resized.

This simple program makes a two element window, the lower half of
which is a gridded set of labels which resize with the window. The
important part is the columnconfigure() and rowconfigure() method
calls on the container widget for the grid.
See 
<URL:http://infohost.nmt.edu/tcc/help/pubs/tkinter/grid-config.html>
http://infohost.nmt.edu/tcc/help/pubs/tkinter/grid-config.html

#!/usr/local/bin/python

from Tkinter import *

root = Tk()
# create a frame (unused, but shared with gridded frame)
f = Frame(height = 100)
f.pack(expand = YES, fill = BOTH)

# create a frame for a gridded display
gf = Frame()
gf.pack(expand = YES, fill = BOTH)

# create a 3 x 4 array of labels, each with a different background
# Make each row and column have equal weights, so they'll
# grow and shrink together
for row in range(3):
    gf.rowconfigure(row, weight = 1)
    for col in range(4):
        gf.columnconfigure(col, weight = 1)
        Label(gf, text = "Row: %d\nCol: %d" % (row, col),
              bg = "#%02x%02x%02x" % ((row * 4 + col) * 16,
                                      (row * 4 + col) * 16,
                                      (row * 4 + col) * 16),
              fg = "#ffffff"
              ).grid(row = row, column = col, sticky = NSEW)



root.mainloop()





-- 
Jim Segrave           (jes at jes-2.demon.nl)




More information about the Python-list mailing list