1grid(3) User Contributed Perl Documentation grid(3)
2
3
4
6 Tk::grid - Geometry manager that arranges widgets in a grid
7
9 $widget->grid?(?widget ...,? ?arg ?...>?)?
10
11 $widget->gridOption?(arg ?,arg ...?)?
12
14 The grid method is used to communicate with the grid geometry manager
15 that arranges widgets in rows and columns inside of another window,
16 called the geometry master (or master window). The grid method can
17 have any of several forms, depending on the option argument:
18
19 $slave->grid(?$slave, ...??, options?)
20 The arguments consist of the optional references to more slave
21 windows followed by pairs of arguments that specify how to manage
22 the slaves. The characters -, x and ^, can be specified instead
23 of a window reference to alter the default location of a $slave, as
24 described in "RELATIVE PLACEMENT", below.
25
26 If any of the slaves are already managed by the geometry manager
27 then any unspecified options for them retain their previous values
28 rather than receiving default values.
29
30 The following options are supported:
31
32 -column => n
33 Insert the $slave so that it occupies the nth column in the
34 grid. Column numbers start with 0. If this option is not
35 supplied, then the $slave is arranged just to the right of
36 previous slave specified on this call to grid, or column
37 "0" if it is the first slave. For each x that immediately
38 precedes the $slave, the column position is incremented by
39 one. Thus the x represents a blank column for this row in
40 the grid.
41
42 -columnspan => n
43 Insert the slave so that it occupies n columns in the grid.
44 The default is one column, unless the window name is
45 followed by a -, in which case the columnspan is
46 incremented once for each immediately following -.
47
48 -in => $other
49 Insert the slave(s) in the master window given by $other.
50 The default is the first slave's parent window.
51
52 -ipadx => amount
53 The amount specifies how much horizontal internal padding
54 to leave on each side of the slave(s). This is space is
55 added inside the slave(s) border. The amount must be a
56 valid screen distance, such as 2 or '.5c'. It defaults to
57 0.
58
59 -ipady => amount
60 The amount specifies how much vertical internal padding to
61 leave on on the top and bottom of the slave(s). This space
62 is added inside the slave(s) border. The amount defaults
63 to 0.
64
65 -padx => amount
66 The amount specifies how much horizontal external padding
67 to leave on each side of the slave(s), in screen units.
68 The amount defaults to 0. This space is added outside the
69 slave(s) border.
70
71 -pady => amount
72 The amount specifies how much vertical external padding to
73 leave on the top and bottom of the slave(s), in screen
74 units. The amount defaults to 0. This space is added
75 outside the slave(s) border.
76
77 -row => n
78 Insert the slave so that it occupies the nth row in the
79 grid. Row numbers start with 0. If this option is not
80 supplied, then the slave is arranged on the same row as the
81 previous slave specified on this call to grid, or the first
82 unoccupied row if this is the first slave.
83
84 -rowspan => n
85 Insert the slave so that it occupies n rows in the grid.
86 The default is one row. If the next grid method contains ^
87 characters instead of $slaves that line up with the columns
88 of this $slave, then the rowspan of this $slave is extended
89 by one.
90
91 -sticky => style
92 If a slave's cell is larger than its requested dimensions,
93 this option may be used to position (or stretch) the slave
94 within its cell. Style is a string that contains zero or
95 more of the characters n, s, e or w. The string can
96 optionally contain spaces or commas, but they are ignored.
97 Each letter refers to a side (north, south, east, or west)
98 that the slave will "stick" to. If both n and s (or e and
99 w) are specified, the slave will be stretched to fill the
100 entire height (or width) of its cavity. The sticky option
101 subsumes the combination of -anchor and -fill that is used
102 by pack. The default is '', which causes the slave to be
103 centered in its cavity, at its requested size.
104
105 $master->gridBbox(?column, row,? ?column2, row2?)
106 With no arguments, the bounding box (in pixels) of the grid is
107 returned. The return value consists of 4 integers. The first two
108 are the pixel offset from the master window (x then y) of the top-
109 left corner of the grid, and the second two integers are the width
110 and height of the grid, also in pixels. If a single column and row
111 is specified on the command line, then the bounding box for that
112 cell is returned, where the top left cell is numbered from zero.
113 If both column and row arguments are specified, then the bounding
114 box spanning the rows and columns indicated is returned.
115
116 $master->gridColumnconfigure(index?, -option=>value, ...?)
117 Query or set the column properties of the index column of the
118 geometry master, $master. The valid options are -minsize, -weight
119 and -pad. If one or more options are provided, then index may be
120 given as a list of column indices to which the configuration
121 options will operate on. The -minsize option sets the minimum
122 size, in screen units, that will be permitted for this column. The
123 -weight option (an integer value) sets the relative weight for
124 apportioning any extra spaces among columns. A weight of zero (0)
125 indicates the column will not deviate from its requested size. A
126 column whose weight is two will grow at twice the rate as a column
127 of weight one when extra space is allocated to the layout. The
128 -uniform option, when a non-empty value is supplied, places
129 the column in a uniform group with other columns that have the same
130 value for -uniform. The space for columns belonging to a uniform
131 group is allocated so that their sizes are always in strict
132 proportion to their -weight values. See THE GRID ALGORITHM
133 below for further details. The -pad option specifies the number of
134 screen units that will be added to the largest window contained
135 completely in that column when the grid geometry manager requests a
136 size from the containing window. If only an option is specified,
137 with no value, the current value of that option is returned. If
138 only the master window and index is specified, all the current
139 settings are returned in an list of "-option value" pairs.
140
141 $slave->gridConfigure(?$slave, ...?, options?)
142 The same as grid method.
143
144 $slave->gridForget?($slave, ...)?
145 Removes each of the $slaves from grid for its master and unmaps
146 their windows. The slaves will no longer be managed by the grid
147 geometry manager. The configuration options for that window are
148 forgotten, so that if the slave is managed once more by the grid
149 geometry manager, the initial default settings are used.
150
151 $slave->gridInfo
152 Returns a list whose elements are the current configuration state
153 of the slave given by $slave in the same option-value form that
154 might be specified to gridConfigure. The first two elements of the
155 list are ``-in=>$master'' where $master is the slave's master.
156
157 $master->gridLocation(x, y)
158 Given x and y values in screen units relative to the master
159 window, the column and row number at that x and y location is
160 returned. For locations that are above or to the left of the grid,
161 -1 is returned.
162
163 $master->gridPropagate?(boolean)?
164 If boolean has a true boolean value such as 1 or on then
165 propagation is enabled for $master, which must be a window name
166 (see "GEOMETRY PROPAGATION" below). If boolean has a false boolean
167 value then propagation is disabled for $master. In either of these
168 cases an empty string is returned. If boolean is omitted then the
169 method returns 0 or 1 to indicate whether propagation is currently
170 enabled for $master. Propagation is enabled by default.
171
172 $master->gridRowconfigure(index?, -option=>value, ...?)
173 Query or set the row properties of the index row of the geometry
174 master, $master. The valid options are -minsize, -weight and -pad.
175 If one or more options are provided, then index may be given as a
176 list of row indeces to which the configuration options will operate
177 on. The -minsize option sets the minimum size, in screen units,
178 that will be permitted for this row. The -weight option (an
179 integer value) sets the relative weight for apportioning any extra
180 spaces among rows. A weight of zero (0) indicates the row will not
181 deviate from its requested size. A row whose weight is two will
182 grow at twice the rate as a row of weight one when extra space is
183 allocated to the layout. The -uniform option, when a non-empty
184 value is supplied, places the row in a uniform group with other
185 rows that have the same value for -uniform. The space for rows
186 belonging to a uniform group is allocated so that their sizes are
187 always in strict proportion to their -weight values. See THE GRID
188 ALGORITHM below for further details. The -pad option specifies the
189 number of screen units that will be added to the largest window
190 contained completely in that row when the grid geometry manager
191 requests a size from the containing window. If only an option is
192 specified, with no value, the current value of that option is
193 returned. If only the master window and index is specified, all
194 the current settings are returned in an list of "option-value"
195 pairs.
196
197 $slave->gridRemove?($slave, ...)?
198 Removes each of the $slaves from grid for its master and unmaps
199 their windows. The slaves will no longer be managed by the grid
200 geometry manager. However, the configuration options for that
201 window are remembered, so that if the slave is managed once more by
202 the grid geometry manager, the previous values are retained.
203
204 $master->gridSize
205 Returns the size of the grid (in columns then rows) for $master.
206 The size is determined either by the $slave occupying the largest
207 row or column, or the largest column or row with a -minsize,
208 -weight, or -pad that is non-zero.
209
210 $master->gridSlaves?(-option=>value)?
211 If no options are supplied, a list of all of the slaves in $master
212 are returned, most recently manages first. -option can be either
213 -row or -column which causes only the slaves in the row (or column)
214 specified by value to be returned.
215
217 The grid method contains a limited set of capabilities that permit
218 layouts to be created without specifying the row and column information
219 for each slave. This permits slaves to be rearranged, added, or
220 removed without the need to explicitly specify row and column
221 information. When no column or row information is specified for a
222 $slave, default values are chosen for -column, -row, -columnspan and
223 -rowspan at the time the $slave is managed. The values are chosen based
224 upon the current layout of the grid, the position of the $slave
225 relative to other $slaves in the same grid method, and the presence of
226 the characters -, ^, and ^ in grid method where $slave names are
227 normally expected.
228
229 - This increases the columnspan of the $slave to the left. Several
230 -'s in a row will successively increase the columnspan. A - may not
231 follow a ^ or a x.
232
233 x This leaves an empty column between the $slave on the left and the
234 $slave on the right.
235
236 ^ This extends the -rowspan of the $slave above the ^'s in the grid.
237 The number of ^'s in a row must match the number of columns spanned
238 by the $slave above it.
239
241 The grid geometry manager lays out its slaves in three steps. In the
242 first step, the minimum size needed to fit all of the slaves is
243 computed, then (if propagation is turned on), a request is made of the
244 master window to become that size. In the second step, the requested
245 size is compared against the actual size of the master. If the sizes
246 are different, then space is added to or taken away from the layout as
247 needed. For the final step, each slave is positioned in its row(s) and
248 column(s) based on the setting of its sticky flag.
249
250 To compute the minimum size of a layout, the grid geometry manager
251 first looks at all slaves whose columnspan and rowspan values are one,
252 and computes the nominal size of each row or column to be either the
253 minsize for that row or column, or the sum of the padding plus the size
254 of the largest slave, whichever is greater. Then the slaves whose
255 rowspans or columnspans are greater than one are examined. If a group
256 of rows or columns need to be increased in size in order to accommodate
257 these slaves, then extra space is added to each row or column in the
258 group according to its weight. For each group whose weights are all
259 zero, the additional space is apportioned equally.
260
261 When multiple rows or columns belong to a uniform group, the space
262 allocated to them is always in proportion to their weights. (A weight
263 of zero is considered to be 1.) In other words, a row or column
264 configured with -weight 1 -uniform a will have exactly the same size as
265 any other row or column configured with -weight 1 -uniform a. A row or
266 column configured with -weight 2 -uniform b will be exactly twice as
267 large as one that is configured with -weight 1 -uniform b.
268
269 More technically, each row or column in the group will have a size
270 equal to k*weight for some constant k. The constant k is chosen so
271 that no row or column becomes smaller than its minimum size. For
272 example, if all rows or columns in a group have the same weight, then
273 each row or column will have the same size as the largest row or column
274 in the group.
275
276 For masters whose size is larger than the requested layout, the
277 additional space is apportioned according to the row and column
278 weights. If all of the weights are zero, the layout is centered within
279 its master. For masters whose size is smaller than the requested
280 layout, space is taken away from columns and rows according to their
281 weights. However, once a column or row shrinks to its minsize, its
282 weight is taken to be zero. If more space needs to be removed from a
283 layout than would be permitted, as when all the rows or columns are at
284 there minimum sizes, the layout is clipped on the bottom and right.
285
287 The grid geometry manager normally computes how large a master must be
288 to just exactly meet the needs of its slaves, and it sets the requested
289 width and height of the master to these dimensions. This causes
290 geometry information to propagate up through a window hierarchy to a
291 top-level window so that the entire sub-tree sizes itself to fit the
292 needs of the leaf windows. However, the gridPropagate method may be
293 used to turn off propagation for one or more masters. If propagation
294 is disabled then grid will not set the requested width and height of
295 the master window. This may be useful if, for example, you wish for a
296 master window to have a fixed size that you specify.
297
299 The master for each slave must either be the slave's parent (the
300 default) or a descendant of the slave's parent. This restriction is
301 necessary to guarantee that the slave can be placed over any part of
302 its master that is visible without danger of the slave being clipped by
303 its parent. In addition, all slaves in one call to grid must have the
304 same master.
305
307 If the master for a slave is not its parent then you must make sure
308 that the slave is higher in the stacking order than the master.
309 Otherwise the master will obscure the slave and it will appear as if
310 the slave hasn't been managed correctly. The easiest way to make sure
311 the slave is higher than the master is to create the master window
312 first: the most recently created window will be highest in the
313 stacking order.
314
316 The grid method is based on ideas taken from the GridBag geometry
317 manager written by Doug. Stein, and the blt_table geometry manager,
318 written by George Howlett.
319
321 Tk::form Tk::pack Tk::place
322
324 geometry manager, location, grid, cell, propagation, size, pack,
325 master, slave
326
327
328
329perl v5.38.0 2023-07-21 grid(3)