Function pack specifies the placement of your widgets: on top of each
other, or side by side.
Use pack to stack two buttons Note that coe is not required here, since we pack two widgets of the same type. |
![]() |
pack [blue];;
pack [red];;
red
" is coded first, it it displayed on top.
side
parameter to pack specifies along which side of the
window the widget should be stuck.`Top
, `Bottom
, `Left
, `Right
,`Top
.pack ~side:`Top [blue];;
pack ~side:`Top [red];;
pack ~side:`Top [blue;red];;
blue
" is placed first, as close to the top as possible.red
" is placed, also as close to the top as possible, given
that "blue
" has already taken the topmost position.Demonstrate several options of the packing method " green " and "yellow " are placed along the left side of
the window," green " being placed before "yellow ".
|
![]() |
When a widget is placed in a window, pack
allocates a rectangular
region for it.
You can force the widget to fill the whole rectangle allocated to
it using the fill
parameter.
For instance,pack [blue] ~side:`Top ~fill:`X ;; pack [red] ~side:`Left ~fill:`Y ;; will extend the buttons as hown here: |
![]() |
Of course changing the order of the pack instructions modifies these rectangles: pack [red] ~side:`Left ~fill:`Y ;; pack [blue] ~side:`Top ~fill:`X ;; we get the following rectangles: |
![]() |
Parameter anchor "anchors" the widget in one side of its
window,e.g., if we change the pack instruction of blue :pack [blue] ~side:`Top ~anchor:`E we see that " blue " is placed at the "east" of its rectangle:
|
![]() |
anchor
can take several values:
`Center | center the widget | |
`E | east corner | |
`N | north corner | |
`Ne | north-east corner | |
`Nw | north-west corner | |
`S | south corner | |
`Se | south-east corner | |
`Sw | south-west corner | |
`W | west corner |
`Center
.`Top
or
`Bottom
, its height is equal to that of its allocated
rectangle.`Left
or `Right
, the
width is equal to that of the rectangle.blue
" in this example,
`W
, `Sw
and `Nw
are equivalent.
You can see that there is a large area unused below "blue ".You can tell pack to expand the allocated rectangle as much as possible with the expand parameter:pack [red] ~side:`Left ~fill:`Y ;; pack [blue] ~side:`Top ~expand:true Note that `Center being the default option," blue " is centered in its rectangle. |
![]() |
With the parameters ipadx and ipady ,
you can increase the size of the widgetbefore allocation of its rectangle: pack [blue] ~side:`Left ~ipadx:20 ~ipady:10 ;; pack [red] ~side:`Left ~ipadx:40 ;; The height of " blue " if increased by 10 pixels, and itswidth by 20 pixels. The width of " red " is increased by 40 pixels.
|
![]() |
Francois dot Thomasset at inria dot fr