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