1grid(n)                      Tk Built-In Commands                      grid(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       grid - Geometry manager that arranges widgets in a grid
9

SYNOPSIS

11       grid option arg ?arg ...?
12______________________________________________________________________________
13

DESCRIPTION

15       The  grid command is used to communicate with the grid geometry manager
16       that arranges widgets in rows and columns  inside  of  another  window,
17       called  the geometry container (or container window).  The grid command
18       can have any of several forms, depending on the option argument:
19
20       grid window ?window ...? ?options?
21              If the first argument to grid is suitable as  the  first  window
22              argument  to  grid  configure,  either  a window name (any value
23              starting with .) or one of the characters x or ^ (see the  RELA‐
24              TIVE  PLACEMENT section below), then the command is processed in
25              the same way as grid configure.
26
27       grid anchor window ?anchor?
28              The anchor value controls how to place the grid within the  con‐
29              tainer  window  when no row/column has any weight.  See THE GRID
30              ALGORITHM below for further details.  The default anchor is nw.
31
32       grid bbox window ?column row? ?column2 row2?
33              With no arguments, the bounding box (in pixels) of the  grid  is
34              returned.   The  return value consists of 4 integers.  The first
35              two are the pixel offset from the container window (x then y) of
36              the top-left corner of the grid, and the second two integers are
37              the width and height of the grid, also in pixels.  If  a  single
38              column and row is specified on the command line, then the bound‐
39              ing box for that cell is returned, where the top  left  cell  is
40              numbered from zero.  If both column and row arguments are speci‐
41              fied, then the bounding box spanning the rows and columns  indi‐
42              cated is returned.
43
44       grid columnconfigure window index ?-option value...?
45              Query  or  set  the column properties of the index column of the
46              geometry container, window.  The  valid  options  are  -minsize,
47              -weight,  -uniform  and  -pad.   If one or more options are pro‐
48              vided, then index may be given as a list of  column  indices  to
49              which the configuration options will operate on.  Indices may be
50              integers, window names or the keyword all. For all  the  options
51              apply  to all columns currently occupied be content windows. For
52              a window name, that window must be a content of  this  container
53              and  the  options apply to all columns currently occupied be the
54              content.  The -minsize option sets the minimum size,  in  screen
55              units,  that will be permitted for this column.  The -weight op‐
56              tion (an integer value) sets the relative weight for  apportion‐
57              ing  any extra spaces among columns.  A weight of zero (0) indi‐
58              cates the column will not deviate from its  requested  size.   A
59              column whose weight is two will grow at twice the rate as a col‐
60              umn of weight one when extra space is allocated to  the  layout.
61              The  -uniform option, when a non-empty value is supplied, places
62              the column in a uniform group with other columns that  have  the
63              same  value  for -uniform.  The space for columns belonging to a
64              uniform group is allocated so that their  sizes  are  always  in
65              strict  proportion  to their -weight values.  See THE GRID ALGO‐
66              RITHM below for further details.  The -pad option specifies  the
67              number  of screen units that will be added to the largest window
68              contained completely in that column when the grid geometry  man‐
69              ager requests a size from the containing window.  If only an op‐
70              tion is specified, with no value, the current value of that  op‐
71              tion  is  returned.   If  only the container window and index is
72              specified, all the current settings are returned in  a  list  of
73              “-option value” pairs.
74
75       grid configure window ?window ...? ?options?
76              The  arguments  consist of the names of one or more content win‐
77              dows followed by pairs of arguments that specify how  to  manage
78              the  content.   The characters -,  x and ^, can be specified in‐
79              stead of a window name to alter the default location of  a  win‐
80              dow, as described in the RELATIVE PLACEMENT section, below.  The
81              following options are supported:
82
83              -column n
84                     Insert the window so that it occupies the nth  column  in
85                     the  grid.   Column numbers start with 0.  If this option
86                     is not supplied, then the window is arranged just to  the
87                     right  of previous window specified on this call to grid,
88                     or column “0” if it is the first window.  For each x that
89                     immediately  precedes  the window, the column position is
90                     incremented by one.  Thus the x represents a blank column
91                     for this row in the grid.
92
93              -columnspan n
94                     Insert  the  window  so that it occupies n columns in the
95                     grid.  The default is one column, unless the window  name
96                     is  followed  by a -, in which case the columnspan is in‐
97                     cremented once for each immediately following -.
98
99              -in container
100                     Insert the window(s) in the  container  window  given  by
101                     container.  The default is the first window's parent win‐
102                     dow.
103
104              -ipadx amount
105                     The amount specifies how much horizontal internal padding
106                     to  leave  on each side of the content.  This is space is
107                     added inside the content border.  The amount  must  be  a
108                     valid  screen distance, such as 2 or .5c.  It defaults to
109                     0.
110
111              -ipady amount
112                     The amount specifies how much vertical  internal  padding
113                     to  leave  on  the  top  and bottom of the content.  This
114                     space is added inside the  content  border.   The  amount
115                     defaults to 0.
116
117              -padx amount
118                     The amount specifies how much horizontal external padding
119                     to leave on each side of the content,  in  screen  units.
120                     Amount may be a list of two values to specify padding for
121                     left and right separately.  The  amount  defaults  to  0.
122                     This space is added outside the content border.
123
124              -pady amount
125                     The  amount  specifies how much vertical external padding
126                     to leave on the top and bottom of the content, in  screen
127                     units.   Amount  may  be  a list of two values to specify
128                     padding for top and bottom separately.   The  amount  de‐
129                     faults  to  0.   This  space is added outside the content
130                     border.
131
132              -row n Insert the content so that it occupies the nth row in the
133                     grid.   Row  numbers start with 0.  If this option is not
134                     supplied, then the content is arranged on the same row as
135                     the  previous  content specified on this call to grid, or
136                     the next row after the highest occupied row  if  this  is
137                     the first content.
138
139              -rowspan n
140                     Insert  the  content  so  that  it occupies n rows in the
141                     grid.  The default is one row.  If the next grid  command
142                     contains  ^  characters  instead  of content that line up
143                     with the columns of this content,  then  the  rowspan  of
144                     this content is extended by one.
145
146              -sticky style
147                     If  a  content's cell is larger than its requested dimen‐
148                     sions, this option may be used to position  (or  stretch)
149                     the  content  within  its  cell.  Style  is a string that
150                     contains zero or more of the characters n,  s,  e  or  w.
151                     The  string can optionally contains spaces or commas, but
152                     they are ignored.  Each letter refers to a  side  (north,
153                     south,  east,  or west) that the content will “stick” to.
154                     If both n and s (or e and w) are specified,  the  content
155                     will be stretched to fill the entire height (or width) of
156                     its cavity.  The -sticky option subsumes the  combination
157                     of  -anchor  and -fill that is used by pack.  The default
158                     is “”, which causes the content to  be  centered  in  its
159                     cavity, at its requested size.
160
161              If any of the content is already managed by the geometry manager
162              then any unspecified options for them retain their previous val‐
163              ues rather than receiving default values.
164
165       grid forget window ?window ...?
166              Removes  each of the windows from grid for its container and un‐
167              maps their windows.  The content will no longer  be  managed  by
168              the  grid  geometry manager.  The configuration options for that
169              window are forgotten, so that if the window is managed once more
170              by  the  grid geometry manager, the initial default settings are
171              used.
172
173       grid info window
174              Returns a list whose  elements  are  the  current  configuration
175              state  of  the  content given by window in the same option-value
176              form that might be specified to grid configure.  The  first  two
177              elements  of the list are “-in container” where container is the
178              windows's container window.
179
180       grid location window x y
181              Given  x and y values in screen units relative to the  container
182              window,  the  column  and row number at that x and y location is
183              returned.  For locations that are above or to the  left  of  the
184              grid, -1 is returned.
185
186       grid propagate window ?boolean?
187              If  boolean has a true boolean value such as 1 or on then propa‐
188              gation is enabled for window, which must be a window  name  (see
189              GEOMETRY  PROPAGATION  below).   If  boolean has a false boolean
190              value then propagation is disabled for  window.   In  either  of
191              these  cases an empty string is returned.  If boolean is omitted
192              then the command returns 0 or 1 to indicate whether  propagation
193              is  currently enabled for window.  Propagation is enabled by de‐
194              fault.
195
196       grid rowconfigure window index ?-option value...?
197              Query or set the row properties of the index row of the geometry
198              window,  window.  The valid options are -minsize, -weight, -uni‐
199              form and -pad.  If one or more options are provided, then  index
200              may be given as a list of row indices to which the configuration
201              options will operate on.  Indices may be integers, window  names
202              or  the  keyword all. For all the options apply to all rows cur‐
203              rently occupied by content windows. For a window name, that win‐
204              dow  must  be a content window of this container and the options
205              apply to all rows currently occupied by  the  container  window.
206              The -minsize option sets the minimum size, in screen units, that
207              will be permitted for this row.  The -weight option (an  integer
208              value)  sets the relative weight for apportioning any extra spa‐
209              ces among rows.  A weight of zero (0) indicates the row will not
210              deviate from its requested size.  A row whose weight is two will
211              grow at twice the rate as a row of weight one when  extra  space
212              is  allocated  to  the layout.  The -uniform option, when a non-
213              empty value is supplied, places the row in a uniform group  with
214              other rows that have the same value for -uniform.  The space for
215              rows belonging to a uniform group is  allocated  so  that  their
216              sizes  are  always in strict proportion to their -weight values.
217              See THE GRID ALGORITHM below for further details.  The -pad  op‐
218              tion  specifies the number of screen units that will be added to
219              the largest window contained completely in  that  row  when  the
220              grid  geometry  manager requests a size from the containing win‐
221              dow.  If only an option is specified, with no value, the current
222              value  of that option is returned.  If only the container window
223              and index is specified, all the current settings are returned in
224              a list of “-option value” pairs.
225
226       grid remove window ?window ...?
227              Removes  each of the windows from grid for its container and un‐
228              maps their windows.  The content will no longer  be  managed  by
229              the  grid  geometry manager.  However, the configuration options
230              for that window are remembered, so that if the content window is
231              managed  once  more  by  the grid geometry manager, the previous
232              values are retained.
233
234       grid size container
235              Returns the size of the grid (in columns  then  rows)  for  con‐
236              tainer.   The size is determined either by the content occupying
237              the largest row or column, or the largest column or row  with  a
238              -minsize, -weight, or -pad that is non-zero.
239
240       grid slaves window ?-option value?
241              If no options are supplied, a list of all of the content in win‐
242              dow are returned, most recently managed first.   Option  can  be
243              either  -row or -column which causes only the content in the row
244              (or column) specified by value to be returned.                   │
245
246       grid content window ?-option value?                                     │
247              Synonym for grid slaves window ?-option value?.
248

RELATIVE PLACEMENT

250       The grid command contains a limited set  of  capabilities  that  permit
251       layouts to be created without specifying the row and column information
252       for each content.  This permits content to be rearranged, added, or re‐
253       moved  without  the  need to explicitly specify row and column informa‐
254       tion.  When no column or row information is specified  for  a  content,
255       default  values  are chosen for -column, -row, -columnspan and -rowspan
256       at the time the content is managed. The values are  chosen  based  upon
257       the current layout of the grid, the position of the content relative to
258       other contents in the same grid command, and the presence of the  char‐
259       acters -, x, and ^ in grid command where content names are normally ex‐
260       pected.
261
262              -      This increases the -columnspan  of  the  content  to  the
263                     left.   Several  -'s  in a row will successively increase
264                     the number of columns spanned. A - may not follow a ^  or
265                     a  x,  nor  may  it be the first content argument to grid
266                     configure.
267
268              x      This leaves an empty column between the  content  on  the
269                     left and the content on the right.
270
271              ^      This extends the -rowspan of the content above the ^'s in
272                     the grid.  The number of ^'s in a row must match the num‐
273                     ber of columns spanned by the content above it.
274

THE GRID ALGORITHM

276       The  grid geometry manager lays out its content in three steps.  In the
277       first step, the minimum size needed to fit all of the content  is  com‐
278       puted,  then  (if  propagation  is turned on), a request is made of the
279       container window to become that size.  In  the  second  step,  the  re‐
280       quested  size is compared against the actual size of the container.  If
281       the sizes are different, then spaces is added to or taken away from the
282       layout  as  needed.   For the final step, each content is positioned in
283       its row(s) and column(s) based on the setting of its sticky flag.
284
285       To compute the minimum size of a  layout,  the  grid  geometry  manager
286       first  looks  at  all content whose -columnspan and -rowspan values are
287       one, and computes the nominal size of each row or column to  be  either
288       the  minsize for that row or column, or the sum of the padding plus the
289       size of the largest content, whichever is greater.  After that the rows
290       or columns in each uniform group adapt to each other.  Then the content
291       whose row-spans or column-spans are greater than one are examined.   If
292       a group of rows or columns need to be increased in size in order to ac‐
293       commodate these content, then extra space is added to each row or  col‐
294       umn in the group according to its weight.  For each group whose weights
295       are all zero, the additional space is apportioned equally.
296
297       When multiple rows or columns belong to a uniform group, the space  al‐
298       located  to them is always in proportion to their weights. (A weight of
299       zero is considered to be 1.)  In other words, a row or  column  config‐
300       ured  with  -weight 1 -uniform a will have exactly the same size as any
301       other row or column configured with -weight 1 -uniform  a.   A  row  or
302       column  configured  with  -weight 2 -uniform b will be exactly twice as
303       large as one that is configured with -weight 1 -uniform b.
304
305       More technically, each row or column in the  group  will  have  a  size
306       equal  to  k*weight  for  some constant k.  The constant k is chosen so
307       that no row or column becomes smaller than its minimum size.  For exam‐
308       ple,  if all rows or columns in a group have the same weight, then each
309       row or column will have the same size as the largest row or  column  in
310       the group.
311
312       For  containers whose size is larger than the requested layout, the ad‐
313       ditional space is apportioned according to the row and column  weights.
314       If  all  of  the weights are zero, the layout is placed within its con‐
315       tainer according to the anchor value.  For  containers  whose  size  is
316       smaller than the requested layout, space is taken away from columns and
317       rows according to their weights.  However, once a column or row shrinks
318       to its minsize, its weight is taken to be zero.  If more space needs to
319       be removed from a layout than would be permitted, as when all the  rows
320       or columns are at their minimum sizes, the layout is placed and clipped
321       according to the anchor value.
322

GEOMETRY PROPAGATION

324       The grid geometry manager normally computes how large a container  must
325       be  to  just exactly meet the needs of its content, and it sets the re‐
326       quested width and height of the container to  these  dimensions.   This
327       causes  geometry information to propagate up through a window hierarchy
328       to a top-level window so that the entire sub-tree sizes itself  to  fit
329       the needs of the leaf windows.  However, the grid propagate command may
330       be used to turn off propagation for one or more containers.  If  propa‐
331       gation  is  disabled  then  grid  will  not set the requested width and
332       height of the container window.  This may be useful  if,  for  example,
333       you wish for a container window to have a fixed size that you specify.
334

RESTRICTIONS ON CONTAINER WINDOWS

336       The container for each content must either be the content's parent (the
337       default) or a descendant of the content's parent.  This restriction  is
338       necessary  to guarantee that the content can be placed over any part of
339       its container that is visible  without  danger  of  the  content  being
340       clipped  by  its  parent.  In addition, all content in one call to grid
341       must have the same container.
342

STACKING ORDER

344       If the container for a content is not its parent  then  you  must  make
345       sure  that  the  content  is higher in the stacking order than the con‐
346       tainer.  Otherwise the container will obscure the content and  it  will
347       appear  as  if the content has not been managed correctly.  The easiest
348       way to make sure the content is higher than the container is to  create
349       the  container  window first:  the most recently created window will be
350       highest in the stacking order.
351

CREDITS

353       The grid command is based on ideas taken from the GridBag geometry man‐
354       ager  written by Doug. Stein, and the blt_table geometry manager, writ‐
355       ten by George Howlett.
356

EXAMPLES

358       A toplevel window containing a text widget and two scrollbars:
359
360              # Make the widgets
361              toplevel .t
362              text .t.txt -wrap none -xscroll {.t.h set} -yscroll {.t.v set}
363              scrollbar .t.v -orient vertical   -command {.t.txt yview}
364              scrollbar .t.h -orient horizontal -command {.t.txt xview}
365
366              # Lay them out
367              grid .t.txt .t.v -sticky nsew
368              grid .t.h        -sticky nsew
369
370              # Tell the text widget to take all the extra room
371              grid rowconfigure    .t .t.txt -weight 1
372              grid columnconfigure .t .t.txt -weight 1
373
374       Three widgets of equal width, despite their different “natural” widths:
375
376              button .b -text "Foo"
377              entry .e -textvariable foo ; set foo "Hello World!"
378              label .l -text "This is a fairly long piece of text"
379
380              grid .b .e .l -sticky ew
381              grid columnconfigure . "all" -uniform allTheSame
382

SEE ALSO

384       pack(n), place(n)
385

KEYWORDS

387       geometry manager, location, grid, cell, propagation, size, pack
388
389
390
391Tk                                    8.5                              grid(n)
Impressum