1pack(n) Tk Built-In Commands pack(n)
2
3
4
5______________________________________________________________________________
6
8 pack - Geometry manager that packs around edges of cavity
9
11 pack option arg ?arg ...?
12_________________________________________________________________
13
14
16 The pack command is used to communicate with the packer, a geometry
17 manager that arranges the children of a parent by packing them in order
18 around the edges of the parent. The pack command can have any of sev‐
19 eral forms, depending on the option argument:
20
21 pack slave ?slave ...? ?options?
22 If the first argument to pack is a window name (any value start‐
23 ing with ``.''), then the command is processed in the same way
24 as pack configure.
25
26 pack configure slave ?slave ...? ?options?
27 The arguments consist of the names of one or more slave windows
28 followed by pairs of arguments that specify how to manage the
29 slaves. See ``THE PACKER ALGORITHM'' below for details on how
30 the options are used by the packer. The following options are
31 supported:
32
33 -after other
34 Other must the name of another window. Use its master as
35 the master for the slaves, and insert the slaves just
36 after other in the packing order.
37
38 -anchor anchor
39 Anchor must be a valid anchor position such as n or sw;
40 it specifies where to position each slave in its parcel.
41 Defaults to center.
42
43 -before other
44 Other must the name of another window. Use its master as
45 the master for the slaves, and insert the slaves just
46 before other in the packing order.
47
48 -expand boolean
49 Specifies whether the slaves should be expanded to con‐
50 sume extra space in their master. Boolean may have any
51 proper boolean value, such as 1 or no. Defaults to 0.
52
53 -fill style
54 If a slave's parcel is larger than its requested dimen‐
55 sions, this option may be used to stretch the slave.
56 Style must have one of the following values:
57
58 none Give the slave its requested dimensions plus any
59 internal padding requested with -ipadx or -ipady.
60 This is the default.
61
62 x Stretch the slave horizontally to fill the entire
63 width of its parcel (except leave external padding
64 as specified by -padx).
65
66 y Stretch the slave vertically to fill the entire
67 height of its parcel (except leave external pad‐
68 ding as specified by -pady).
69
70 both Stretch the slave both horizontally and verti‐
71 cally.
72
73 -in other
74 Insert the slave(s) at the end of the packing order for
75 the master window given by other.
76
77 -ipadx amount
78 Amount specifies how much horizontal internal padding to
79 leave on each side of the slave(s). Amount must be a
80 valid screen distance, such as 2 or .5c. It defaults to
81 0.
82
83 -ipady amount
84 Amount specifies how much vertical internal padding to
85 leave on each side of the slave(s). Amount defaults to
86 0.
87
88 -padx amount
89 Amount specifies how much horizontal external padding to
90 leave on each side of the slave(s). Amount may be a list
91 of two values to specify padding for left and right sepa‐
92 rately. Amount defaults to 0.
93
94 -pady amount
95 Amount specifies how much vertical external padding to
96 leave on each side of the slave(s). Amount may be a list
97 of two values to specify padding for top and bottom sepa‐
98 rately. Amount defaults to 0.
99
100 -side side
101 Specifies which side of the master the slave(s) will be
102 packed against. Must be left, right, top, or bottom.
103 Defaults to top.
104
105 If no -in, -after or -before option is specified then each of
106 the slaves will be inserted at the end of the packing list for
107 its parent unless it is already managed by the packer (in which
108 case it will be left where it is). If one of these options is
109 specified then all the slaves will be inserted at the specified
110 point. If any of the slaves are already managed by the geometry
111 manager then any unspecified options for them retain their pre‐
112 vious values rather than receiving default values.
113
114 pack forget slave ?slave ...?
115 Removes each of the slaves from the packing order for its master
116 and unmaps their windows. The slaves will no longer be managed
117 by the packer.
118
119 pack info slave
120 Returns a list whose elements are the current configuration
121 state of the slave given by slave in the same option-value form
122 that might be specified to pack configure. The first two ele‐
123 ments of the list are ``-in master'' where master is the slave's
124 master.
125
126 pack propagate master ?boolean?
127 If boolean has a true boolean value such as 1 or on then propa‐
128 gation is enabled for master, which must be a window name (see
129 ``GEOMETRY PROPAGATION'' below). If boolean has a false boolean
130 value then propagation is disabled for master. In either of
131 these cases an empty string is returned. If boolean is omitted
132 then the command returns 0 or 1 to indicate whether propagation
133 is currently enabled for master. Propagation is enabled by
134 default.
135
136 pack slaves master
137 Returns a list of all of the slaves in the packing order for
138 master. The order of the slaves in the list is the same as
139 their order in the packing order. If master has no slaves then
140 an empty string is returned.
141
143 For each master the packer maintains an ordered list of slaves called
144 the packing list. The -in, -after, and -before configuration options
145 are used to specify the master for each slave and the slave's position
146 in the packing list. If none of these options is given for a slave
147 then the slave is added to the end of the packing list for its parent.
148
149 The packer arranges the slaves for a master by scanning the packing
150 list in order. At the time it processes each slave, a rectangular area
151 within the master is still unallocated. This area is called the cav‐
152 ity; for the first slave it is the entire area of the master.
153
154 For each slave the packer carries out the following steps:
155
156 [1] The packer allocates a rectangular parcel for the slave along
157 the side of the cavity given by the slave's -side option. If
158 the side is top or bottom then the width of the parcel is the
159 width of the cavity and its height is the requested height of
160 the slave plus the -ipady and -pady options. For the left or
161 right side the height of the parcel is the height of the cavity
162 and the width is the requested width of the slave plus the
163 -ipadx and -padx options. The parcel may be enlarged further
164 because of the -expand option (see ``EXPANSION'' below)
165
166 [2] The packer chooses the dimensions of the slave. The width will
167 normally be the slave's requested width plus twice its -ipadx
168 option and the height will normally be the slave's requested
169 height plus twice its -ipady option. However, if the -fill
170 option is x or both then the width of the slave is expanded to
171 fill the width of the parcel, minus twice the -padx option. If
172 the -fill option is y or both then the height of the slave is
173 expanded to fill the width of the parcel, minus twice the -pady
174 option.
175
176 [3] The packer positions the slave over its parcel. If the slave is
177 smaller than the parcel then the -anchor option determines where
178 in the parcel the slave will be placed. If -padx or -pady is
179 non-zero, then the given amount of external padding will always
180 be left between the slave and the edges of the parcel.
181
182 Once a given slave has been packed, the area of its parcel is sub‐
183 tracted from the cavity, leaving a smaller rectangular cavity for the
184 next slave. If a slave doesn't use all of its parcel, the unused space
185 in the parcel will not be used by subsequent slaves. If the cavity
186 should become too small to meet the needs of a slave then the slave
187 will be given whatever space is left in the cavity. If the cavity
188 shrinks to zero size, then all remaining slaves on the packing list
189 will be unmapped from the screen until the master window becomes large
190 enough to hold them again.
191
193 If a master window is so large that there will be extra space left over
194 after all of its slaves have been packed, then the extra space is dis‐
195 tributed uniformly among all of the slaves for which the -expand option
196 is set. Extra horizontal space is distributed among the expandable
197 slaves whose -side is left or right, and extra vertical space is dis‐
198 tributed among the expandable slaves whose -side is top or bottom.
199
201 The packer normally computes how large a master must be to just exactly
202 meet the needs of its slaves, and it sets the requested width and
203 height of the master to these dimensions. This causes geometry infor‐
204 mation to propagate up through a window hierarchy to a top-level window
205 so that the entire sub-tree sizes itself to fit the needs of the leaf
206 windows. However, the pack propagate command may be used to turn off
207 propagation for one or more masters. If propagation is disabled then
208 the packer will not set the requested width and height of the packer.
209 This may be useful if, for example, you wish for a master window to
210 have a fixed size that you specify.
211
213 The master for each slave must either be the slave's parent (the
214 default) or a descendant of the slave's parent. This restriction is
215 necessary to guarantee that the slave can be placed over any part of
216 its master that is visible without danger of the slave being clipped by
217 its parent.
218
220 If the master for a slave is not its parent then you must make sure
221 that the slave is higher in the stacking order than the master. Other‐
222 wise the master will obscure the slave and it will appear as if the
223 slave hasn't been packed correctly. The easiest way to make sure the
224 slave is higher than the master is to create the master window first:
225 the most recently created window will be highest in the stacking order.
226 Or, you can use the raise and lower commands to change the stacking
227 order of either the master or the slave.
228
230 # Make the widgets
231 label .t -text "This widget is at the top" -bg red
232 label .b -text "This widget is at the bottom" -bg green
233 label .l -text "Left\nHand\nSide"
234 label .r -text "Right\nHand\nSide"
235 text .mid
236 # Lay them out
237 pack .t -side top -fill x
238 pack .b -side bottom -fill x
239 pack .l -side left -fill y
240 pack .r -side right -fill y
241 pack .mid -expand 1 -fill both
242
243
245 grid(n), place(n)
246
247
249 geometry manager, location, packer, parcel, propagation, size
250
251
252
253Tk 4.0 pack(n)