Navigation Logo 13.6  The Cavity Navigation Logo

 

 

When the root window first appears, it seems to be a hole with nothing in it. When viewed from pack, this hole is called the cavity. A cavity is a place where you can put a slicing. Any frame and any Tk window, other than the command window, has a cavity.

According to the cavity paradigm, each newly packed widget goes into a cavity. The size of a cavity is not fixed – it varies as the window is resized. When you pack another widget into a cavity you are placing it on one side of that cavity. The -side option, whose values are "top," "bottom," "left" and "right," is used to determine which side. The widget occupies a slice that fills the whole side of the cavity that was current when it was created. With the creation of a new slice, the new cavity is the old cavity minus this slice.

Although the cavity paradigm is simple and flexible, it is confusing to use. Look at Figure 13.6a and try to do the following: Point to the cavity or cavities. Explain why the grey box on the left is not centered vertically. Explain what will happen when a user expands the window.

Figure 13.6a: A use of the cavity paradigm.
pack [box . grey50]  -expand true
pack [box . grey50] -side left
pack [frame .fr] -side bottom -expand true -fill both
pack [box . black] -side left 
pack [box . white] -side right
pack [box .fr black] -side right
pack [box .fr white] -side right 

The cavity paradigm is not easy to master and does not encourage windows that are intellectually manageable. The slicing paradigm, on the other hand, has both these pleasant properties. Unfortunately, the slicing paradigm requires extra frames if it is to accomplish as much as the cavity paradigm. This section suggests a blending of the two that gives you the flexibility of the cavity paradigm while encouraging you to think in terms of slices.

In this blended paradigm every slice goes into some cavity as described above. The difference is that you think of cavities in terms of slicings. Each slicing may have an attached cavity which is where an additional slice, if any, will be positioned.

Horizontal slicings are not created with just -side top (the default) but also with -side bottom. Whenever -side top is used, the newly created slice is on the top of the attached cavity of the new slicing. Whenever -side bottom is used, the newly created slice is on the bottom of the attached cavity of the new slicing. Each additional slice goes into the attached cavity of the previous version of the slicing.

For vertical slicings the situation is similar. They are created with the "left" and "right" values of the -side option. Whenever -side left is used, the newly created slice is on the left of the attached cavity of the new slicing. Whenever -side right is used, the newly created slice is on the right of the attached cavity of the new slicing. Each additional slice goes into the attached cavity of the previous version of the slicing.

If a vertical slice is put into the attached cavity of a horizontal slicing, the horizontal slicing becomes complete and its attached cavity is lost. If a horizontal slice is put into the attached cavity of a vertical slicing, the vertical slicing becomes complete and its attached cavity is lost.

Exercise 13.6a

Place comments in the script for Figure 13.6a that describe each slicing. After you understand the slicings explain what the window will do when the user expands it. Your explanation should involve attached cavities as well as slices that expand or stretch in their lengthwise direction.

Solution

The solution to this exercise is certainly easier to fathom than the same code as it shown in Figure 13.6a. However, a greater benefit of thinking in terms of slicings may be that you are more likely to pack your windows in ways that can be more easily described. "More easily described" implies "more easily understood."

Exercise 13.6b

Redo Exercise 13.3d but this time begin with a slicing in the opposite direction from your original solution. Also do not create two slices for this original slicing. Complete the first slicing at one slice by slicing in the other direction. Your solution will, therefore, have one fewer invisible frames.

Solution

 

 

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