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

NAME

8       pack - Geometry manager that packs around edges of cavity
9

SYNOPSIS

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

DESCRIPTION

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 window ?window ...? ?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 window ?window ...? ?options?
26              The arguments consist of the names of one or more  content  win‐
27              dows  followed  by pairs of arguments that specify how to manage
28              the content.  See THE PACKER ALGORITHM below for details on  how
29              the  options  are used by the packer.  The following options are
30              supported:
31
32              -after other
33                     Other must the name of another window.  Use its container
34                     as  the container for the content, and insert the content
35                     just 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 content in its par‐
40                     cel.  Defaults to center.
41
42              -before other
43                     Other must the name of another window.  Use its container
44                     as  the container for the content, and insert the content
45                     just before other in the packing order.
46
47              -expand boolean
48                     Specifies whether the content should be expanded to  con‐
49                     sume  extra  space  in their container.  Boolean may have
50                     any proper boolean value, such as 1 or no.   Defaults  to
51                     0.
52
53              -fill style
54                     If a content's parcel is larger than its requested dimen‐
55                     sions, this option may be used to  stretch  the  content.
56                     Style must have one of the following values:
57
58                     none   Give the content its requested dimensions plus any
59                            internal padding requested with -ipadx or  -ipady.
60                            This is the default.
61
62                     x      Stretch  the  content horizontally to fill the en‐
63                            tire width of its parcel  (except  leave  external
64                            padding as specified by -padx).
65
66                     y      Stretch  the content 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  content both horizontally and verti‐
71                            cally.
72
73              -in container
74                     Insert the window at the end of the packing order for the
75                     container window given by container.
76
77              -ipadx amount
78                     Amount  specifies how much horizontal internal padding to
79                     leave on each side of the  content.   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 content.  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 content.  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 content.  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 container the content 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  content 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 content will be inserted at the specified
110              point.   If any of the content are already managed by the geome‐
111              try manager then any unspecified options for them  retain  their
112              previous values rather than receiving default values.
113
114       pack forget window ?window ...?
115              Removes  each of the windows from the packing order for its con‐
116              tainer and unmaps their windows.  The content will no longer  be
117              managed by the packer.
118
119       pack info window
120              Returns  a  list  whose  elements  are the current configuration
121              state of the window given by window  in  the  same  option-value
122              form  that  might be specified to pack configure.  The first two
123              elements of the list are “-in container” where container is  the
124              window's container.
125
126       pack propagate container ?boolean?
127              If  boolean has a true boolean value such as 1 or on then propa‐
128              gation is enabled for container, which must  be  a  window  name
129              (see  GEOMETRY PROPAGATION below).  If boolean has a false bool‐
130              ean value then propagation is disabled for container.  In either
131              of these cases an empty string is returned.  If boolean is omit‐
132              ted then the command returns 0 or 1 to indicate whether propaga‐
133              tion is currently enabled for container.  Propagation is enabled
134              by default.
135
136       pack slaves window
137              Returns a list of all of the content windows in the packing  or‐
138              der for window.  The order of the content windows in the list is
139              the same as their order in the packing order.  If window has  no
140              content then an empty string is returned.                        │
141
142       pack content window                                                     │
143              Synonym for pack slaves window.
144

THE PACKER ALGORITHM

146       For each container the packer maintains an ordered list of content win‐
147       dows called the packing list.  The -in, -after, and -before  configura‐
148       tion options are used to specify the container for each content and the
149       content's position in the packing list.  If none of  these  options  is
150       given for a content then the content is added to the end of the packing
151       list for its parent.
152
153       The packer arranges the content windows for a container by scanning the
154       packing  list  in order.  At the time it processes each content, a rec‐
155       tangular area within the container is still unallocated.  This area  is
156       called  the cavity;  for the first content it is the entire area of the
157       container.
158
159       For each content the packer carries out the following steps:
160
161       [1]    The packer allocates a rectangular parcel for the content  along
162              the  side of the cavity given by the content's -side option.  If
163              the side is top or bottom then the width of the  parcel  is  the
164              width  of  the  cavity and its height is the requested height of
165              the content plus the -ipady and -pady options.  For the left  or
166              right  side the height of the parcel is the height of the cavity
167              and the width is the requested width of  the  content  plus  the
168              -ipadx  and  -padx  options.  The parcel may be enlarged further
169              because of the -expand option (see EXPANSION below)
170
171       [2]    The packer chooses the dimensions of  the  content.   The  width
172              will  normally  be  the content's requested width plus twice its
173              -ipadx option and the height will normally be the content's  re‐
174              quested  height  plus  twice its -ipady option.  However, if the
175              -fill option is x or both then the width of the content  is  ex‐
176              panded  to  fill  the width of the parcel, minus twice the -padx
177              option.  If the -fill option is y or both then the height of the
178              content is expanded to fill the width of the parcel, minus twice
179              the -pady option.
180
181       [3]    The packer positions the content over its parcel.  If  the  con‐
182              tent  is  smaller than the parcel then the -anchor option deter‐
183              mines where in the parcel the content will be placed.  If  -padx
184              or  -pady is non-zero, then the given amount of external padding
185              will always be left between the content and  the  edges  of  the
186              parcel.
187
188       Once  a  given  content has been packed, the area of its parcel is sub‐
189       tracted from the cavity, leaving a smaller rectangular cavity  for  the
190       next  content.  If a content does not use all of its parcel, the unused
191       space in the parcel will not be used by  subsequent  content.   If  the
192       cavity  should become too small to meet the needs of a content then the
193       content will be given whatever space is left in  the  cavity.   If  the
194       cavity  shrinks to zero size, then all remaining content on the packing
195       list will be unmapped from the screen until the  container  window  be‐
196       comes large enough to hold them again.
197
198   EXPANSION
199       If  a  container window is so large that there will be extra space left
200       over after all of its content have been packed, then the extra space is
201       distributed  uniformly  among  all of the content for which the -expand
202       option is set.  Extra horizontal space is distributed among the expand‐
203       able  content whose -side is left or right, and extra vertical space is
204       distributed among the expandable content whose -side is top or bottom.
205
206   GEOMETRY PROPAGATION
207       The packer normally computes how large a container must be to just  ex‐
208       actly  meet  the  needs of its content, and it sets the requested width
209       and height of the container to these dimensions.  This causes  geometry
210       information  to  propagate up through a window hierarchy to a top-level
211       window so that the entire sub-tree sizes itself to fit the needs of the
212       leaf  windows.  However, the pack propagate command may be used to turn
213       off propagation for one or more containers.  If propagation is disabled
214       then  the  packer  will  not  set the requested width and height of the
215       packer.  This may be useful if, for example, you wish for  a  container
216       window to have a fixed size that you specify.
217

RESTRICTIONS ON CONTAINER WINDOWS

219       The container for each content must either be the content's parent (the
220       default) or a descendant of the content's parent.  This restriction  is
221       necessary  to guarantee that the content can be placed over any part of
222       its container that is visible  without  danger  of  the  content  being
223       clipped by its parent.
224

PACKING ORDER

226       If  the  container  for  a content is not its parent then you must make
227       sure that the content is higher in the stacking  order  than  the  con‐
228       tainer.   Otherwise  the container will obscure the content and it will
229       appear as if the content has not been packed  correctly.   The  easiest
230       way  to make sure the content is higher than the container is to create
231       the container window first:  the most recently created window  will  be
232       highest  in  the  stacking  order.  Or, you can use the raise and lower
233       commands to change the stacking order of either the  container  or  the
234       content.
235

EXAMPLE

237              # Make the widgets
238              label .t -text "This widget is at the top"    -bg red
239              label .b -text "This widget is at the bottom" -bg green
240              label .l -text "Left\nHand\nSide"
241              label .r -text "Right\nHand\nSide"
242              text .mid
243              .mid insert end "This layout is like Java's BorderLayout"
244              # Lay them out
245              pack .t   -side top    -fill x
246              pack .b   -side bottom -fill x
247              pack .l   -side left   -fill y
248              pack .r   -side right  -fill y
249              pack .mid -expand 1    -fill both
250

SEE ALSO

252       grid(n), place(n)
253

KEYWORDS

255       geometry manager, location, packer, parcel, propagation, size
256
257
258
259Tk                                    4.0                              pack(n)
Impressum