LablTk: packing

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.
        

We get the same effect if we specify twice the pack instruction:
pack [blue];;
pack [red];;
As you can expect, if you change the order, you change the output:
if "red" is coded first, it it displayed on top.


The side parameter to pack specifies along which side of the window the widget should be stuck.
Its values are `Top, `Bottom, `Left, `Right,
the default value being `Top.
So that the code above is equivalent to:
pack ~side:`Top [blue];;
pack ~side:`Top [red];;
or:
pack ~side:`Top [blue;red];;
Button "blue" is placed first, as close to the top as possible.
Then "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:


    

The 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
The default value is `Center.
You may observe that, when a widget is packed on `Top or `Bottom, its height is equal to that of its allocated rectangle.
While for a widget packed on `Left or `Right, the width is equal to that of the rectangle.
As a consequence, for the widget "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 widget
before 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 its
width by 20 pixels.
The width of "red" is increased by 40 pixels.
            



There exists another technique to place widgets: see grids further below.

François Thomasset -- INRIA, Rocquencourt -- November 2007
Email: Francois dot Thomasset at inria dot fr