Navigation Logo 13.8  Tricks for Using Pack Navigation Logo

 

 

This section contains two tricks.

Using and Avoiding Frames as Spacing

Figure 13.8a shows a single frame with three white boxes and two expanding frames in between. As shown, the root window has been expanded by the user. The expanding, but empty, frames serve to keep an even spacing between the boxes. This is a fairly common use for a frame. A very similar example was given in Exercise 13.3b.

Figure 13.8a: Frames as spacing.
pack [frame .fr] -fill both
pack [box .fr white] -side left
pack [frame .fr.space1] -side left -fill both -expand true
pack [box .fr white] -side left
pack [frame .fr.space2] -side left -fill both -expand true
pack [box .fr white] -side left 

Frames make good spacing but they are not necessary if what you want to do is put a widget on either end of a slice. To place two widgets so that they stick on either end of a slice, just vary the -side options to get them there.

Exercise 13.8a

Put four white boxes in the corners of the root window so that they keep their size and stick to their corners as the window is expanded.

Solution

Sizing Text-Based Widgets

It sometimes happens that you wish that text-based widgets had height and width dimensions of the same kind as other widgets instead of height and width dimensions that are measured in numbers of characters. You do not get your wish, but you can ask the text-based widget to conform to other measurements. Do the following in the order stated:

  1. declare a frame of the size you want – say its pathname is i FRAME_PATH

  2. execute
    pack propagate FRAME_PATH false
    

  3. pack the text-based widget in the frame so that it expands in both dimensions

Normally, the packer calculates the size needed by a master's slaves and then tries to size the frame accordingly. The size of the subwindows is propagating upwards. When you use pack propagate, the packer will attempt to keep the widget you name the size you have requested with the -height and -width options.

Exercise 13.8b

Create a text widget that is 375 pixels wide and 300 pixels high.

Solution

 

 

[Sample TK Application]
Author's Home Page
Navigation Logo [Book's Cover]
Order from Amazon.