[ Team LiB ] Previous Section Next Section

Gridding, Resizing, and Geometry

The text, listbox, and canvas widgets support geometry gridding. This is an alternate interpretation of the main window geometry that is in terms of grid units, typically characters, as opposed to pixels. The setGrid attribute is a boolean that indicates if gridding should be turned on. The listbox and text widgets define a grid size that matches their character size. Example 44-1 on page 658 sets up gridding for a canvas.

When a widget is gridded, its size is constrained to have a whole number of grid units displayed. The height will be constrained to show a whole number of text lines, and the width will be constrained to show a whole number of average width characters. This affects interactive resizing by users, as well as the various window manger commands (wm) that relate to geometry. When gridding is turned on, the geometry argument (e.g., 24x80) is interpreted as grid units; otherwise, it is interpreted as pixels. The window manager geometry commands are summarized in Table 44-1 on page 659.

The following example creates a listbox with gridded geometry enabled. Try resizing the window in the following example with and without the -setgrid flag, and with and without the wm minsize command, which sets the minimum size of the window. The Scrolled_Listbox procedure is defined in Example 33-3 on page 502.

Example 42-3 A gridded, resizable listbox
wm minsize . 5 3
button .quit -text Quit -command exit
pack .quit -side top -anchor e
Scrolled_Listbox .f -width 10 -height 5 -setgrid true
pack .f -side top -fill both -expand true
    [ Team LiB ] Previous Section Next Section