Chapter 28. The Panedwindow Widget

The panedwindow widget, introduced in Tk 8.4, displays widgets in resizable horizontal or vertical panes.

A panedwindow contains any number of panes, arranged horizontally or vertically. Each pane contains one widget, and each pair of panes is separated by a moveable sash, which causes the widgets on either side of the sash to be resized. When a panedwindow is resized externally — for example, if the user resizes the toplevel containing the panedwindow — space is added or subtracted from the last pane (right-most or bottom-most pane) in the widget.

Using the Panedwindow

The panedwindow is a relatively simple widget, requiring little configuration or programming in most applications. The most frequently used configuration attribute is orient, which determines whether the widget has a horizontal or vertical arrangement of panes. The other frequently used configuration attribute is showHandle. The handle is a small square drawn on the sashes, giving users another visual cue that the sashes are interactive. The default value of showHandle is False on Windows to match its native look and feel. Most other configuration attributes control the size, positioning, and appearance of the handles, the sashes, and the widget in general.

Manipulating the Pane Contents

Once you've created the panedwindow, you add widgets to it with the add operation. You can add multiple widgets with a single add operation. The panedwindow displays each widget added in its own pane, separated by sashes. By default, the widgets are arranged in the order added. However, you can override this behavior with the -after and -before options to insert widgets after or before currently managed widgets. You can add horizontal and vertical padding to the widgets in the panes with -padx and -pady options, just like with other geometry managers. The -minsize attribute allows you to specify a minimum size for managed widgets (in any screen units supported by Tk.) You can also control the position of a widget within its pane with the -sticky attribute, which operates similarly to grid's -sticky attribute. The panedwindow's default -sticky setting is nsew, causing the managed widget to resize to completely fill its pane in both directions.

Note

Manipulating the Pane Contents

Don't pack, grid, or place the widgets in a panedwindow.

A panedwindow widget is not only a container for other widgets, but it is also a geometry manager. It controls the size and position of the widgets that it manages. Therefore, don't use the pack, grid, or place commands to control the widgets that you add to a panedwindow.

Of course, for more complex interfaces, you can add frames as the managed widgets of a panedwindow, and then pack, grid, or place other widgets within those frames. As an example, consider a layout with two text widgets. We'd like each text widget to have horizontal and vertical scrollbars, which is a natural application of grid. But then we want the entire layout managed by a 2-pane vertical panedwindow. In this case, we'll use a labelframe widget to contain each gridded text-and-scrollbar assembly, and then add each labelframe as a managed widget of our panedwindow. The result is shown in Example 28-1.

Example 28-1. A panedwindow with complex managed widgets

A panedwindow with complex managed widgets
# Create the panedwindow to manage the entire display

panedwindow .p -orient vertical -showhandle 1
pack .p -expand yes -fill both

# Create 2 labelframe widgets, each containing a
# gridded text and scrollbar assembly.

foreach {w label} {code "Code:" notes "Notes:"} {
   set f [labelframe .p.$w -text $label]
   text $f.t -height 10 -width 40 
      -wrap none -font {courier 12} 
      -xscrollcommand [list $f.xbar set] 
      -yscrollcommand [list $f.ybar set]
   scrollbar $f.xbar -orient horizontal 
      -command [list $f.t xview]
   scrollbar $f.ybar -orient vertical 
      -command [list $f.t yview]

   grid $f.t -row 0 -column 0 -sticky news -padx 2 -pady 2
   grid $f.ybar -row 0 -column 1 -sticky ns -padx 2 -pady 2
   grid $f.xbar -row 1 -column 0 -sticky ew -padx 2 -pady 2
   grid columnconfigure $f 0 -weight 1
   grid rowconfigure $f 0 -weight 1

   # Add the frame assembly to the panedwindow

   .p add $f -minsize 1i -padx 4 -pady 6
}

The forget operation removes widgets from a panedwindow. The widgets aren't destroyed, but they are no longer managed by the paned window, and the pane they formerly occupied is removed from the panedwindow. You can also get a list of the widgets currently managed by a panedwindow (in the order in which they appear) with the panes operation.

Note

A panedwindow with complex managed widgets

Create the managed widgets as children of the panedwindow.

For best results, create the widgets managed by a panedwindow as children of that panedwindow. Tk then automatically handles the stacking order for windows so that the child appears on top of the panedwindow. If you don't create the managed widget as a child of the panedwindow, you either need to create the managed widget after the panedwindow, or else use the raise command to raise the managed widget above the panedwindow, as discussed in “Window Stacking Order” on page 409.

Programming Panedwindow Widgets

Table 28-1 summarizes the operations for programming a panedwindow. In the table, $w is a panedwindow widget and win is a widget managed by the panedwindow.

Table 28-1. Panedwindow operations

$w add win ?win...? ?option value...?

Adds one or more widgets to the panedwindow, each in a separate pane, with options as described in Table 28-2.

$w cget option

Returns the value of the configuration option as described in Table 28-3.

$w configure ?option value...?

Queries or modifies the panedwindow configuration, with options as described in Table 28-3.

$w forget win ?win...?

Removes the pane(s) containing widget(s) from the panedwindow.

$w identify x y

Identifies the panedwindow component underneath the specified point.

$w panecget win option

Returns the value of the widget's configuration option as described in Table 28-2.

$w paneconfigure index ?option? ?value? ?...?

Queries or modifies the widget's configuration options as described in Table 28-2.

$w panes

Returns an ordered list of the widgets managed by the panedwindow.

$w proxy coord

Returns the current x and y coordinate pair for the sash proxy, used for rubberband-style pane resizing.

$w proxy forget

Removes the sash proxy from the display.

$w proxy place x y

Places the sash proxy at the given coordinates.

$w sash coord index

Returns the current x and y coordinate pair for the sash indicated by index.

$w sash dragto index x y

Moves the sash from the previous mark position.

$w sash mark index x y

Starts a sash movement operation. index is the sash to move, and x and y are widget-relative screen coordinates.

$w sash place index x y

Places the indicated sash at the given coordinates.

Table 28-2 summarizes the panedwindow options for managed widgets. These are set when adding a widget to the paned window with the add operation or afterwards with paneconfigure operation. The current settings are returned by the panecget operation.

Table 28-2. Panedwindow managed widget options

-after win

Inserts the widget after the specified win.

-before win

Inserts the widget before the specified win.

-height size

Height of the widget, including its border, in screen units. The actual widget height may vary based on -sticky settings, panedwindow resizing, and sash movement.

-minsize size

Minimum widget size of the widget in the paned dimension, specified in screen units.

-padx size

External widget padding in the X direction, in screen units.

-pady size

External widget padding in the Y direction, in screen units.

-sticky how

Positions the widget next to any combination of north (n), south (s), east (w), and west (e) sides of the pane. Use {} for center. If opposing directions are specified (e.g., ns), the widget stretches to fill in those directions. Default: nsew.

-width size

Width of the widget, including its border, in screen units. The actual widget width may vary based on -sticky settings, panedwindow resizing, and sash movement.

Panedwindow Attributes

Table 28-3 lists the panedwindow widget attributes. The table uses the resource name for the attribute, which has capitals at internal word boundaries. In Tcl commands these options are specified with a dash and all lowercase.

Table 28-3. Panedwindow attributes

background

Background color (also bg).

borderWidth

Extra space around the edge of the widget, in screen units.

cursor

Cursor to display when mouse is over the widget.

handlePad

When sash handles are drawn, the distance in screen units from the top or left end of the sash (depending on the orientation) at which to draw the handle.

handleSize

The size of a sash handle, in screen units. Handles are always drawn as squares.

height

Height of the widget in screen units.

opaqueResize

Boolean. True indicates the panes should resize as a sash is moved. False (default) indicates resizing is deferred until the sash is placed.

orient

horizontal or vertical

relief

flat, sunken, raised, groove, solid, or ridge.

sashCursor

Cursor to display over a sash. Defaults to a double-sided arrow.

sashPad

Padding on both sides of a sash.

sashRelief

Relief style for sashes. flat, sunken, raised (default), groove, solid, or ridge.

sashWidth

Width of each sash, in screen units.

showHandle

Boolean, whether or not to show the sash handles. Defaults to False on Windows, and True on other platforms.

width

Width of the widget in screen units.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.239