Pmw.PanedWidget

Name

Pmw.PanedWidget() - frame subdivided into several resizable panes

Inherits

Pmw.MegaWidget

Description

This class creates a manager widget for containing resizable frames, known as panes. Each pane may act as the container for other widgets. The user may resize the panes by dragging a small rectangle (the handle) or the line between the panes (the separator). The panes may be arranged horizontally or vertically.

Options

Options for this megawidget and its base classes are described below.

command
Specifies a function to be called whenever the size of any of the panes changes. The function is called with a single argument, being a list of the sizes of the panes, in order. For vertical orientation, the size is the height of the panes. For horizontal orientation, the size is the width of the panes. The default is None.

handlesize
Initialisation option. The default is 8.

orient
Initialisation option. Specifies the orientation of the paned widget. This may be 'horizontal' or 'vertical'. If 'vertical', the panes are stacked above and below each other, otherwise the panes are laid out side by side. The default is 'vertical'.

separatorrelief
Initialisation option. Specifies the relief of the line separating the panes. The default is 'sunken'.

separatorthickness
Initialisation option. The default is 2.

Pane options

Each pane has the following options. These may be set when creating or configuring a pane. The value of each option may be an integer, which specifies a pane size in pixels, or a real number between 0.0 and 1.0, which specifies a pane size proportional to the size of the entire paned widget.

size
Specifies the initial size of the pane. The default is 0.

min
Specifies the minimum size of the pane. The default is 0.

max
Specifies the maximum size of the pane. The default is a very large number.

Components

Components created by this megawidget and its base classes are described below.

hull
This acts as the body for the entire megawidget. Other components are created as children of the hull to further specialise the widget. By default, this component is a Tkinter.Frame.

Dynamic components

Frame, separator and handle components are created dynamically by the add() and insert() methods. The components are of type Tkinter.Frame and are created with component groups of Frame, Separator and Handle respectively.

Methods

Only methods specific to this megawidget are described below. For a description of its inherited methods, see the manuals for its base classes.

add(name, **kw)
Add a pane to the end of the paned widget as a component named name. This is equivalent to calling insert() with before set to the current number of panes. The method returns the name component widget.

configurepane(name, **kw)
Configure the pane specified by name, where name is either an integer, specifying the index of the pane, or a string, specifying the name of the pane. The keyword arguments specify the new values for the options for the pane. These options are described in the Pane options section.

delete(name)
Delete the pane specified by name, where name is either an integer, specifying the index of the pane, or a string, specifying the name of the pane.

If the pane deleted was not the only pane in the paned widget, also delete the separator and handle components named separator-n and handle-n, where n is the number of panes remaining.

insert(name, before = 0, **kw)
Add a pane to the paned widget as a component named name. The pane is added just before the pane specified by before, where before may be either an integer, specifying the index of the pane, or a string, specifying the name of the pane. The keyword arguments specify the initial values for the options for the new pane. These options are described in the Pane options section. To add a pane to the end of the paned widget, use add().

The new pane is created as a Tkinter.Frame component named name. If this is not the only pane, a separator and handle are also created as components named separator-n and handle-n, where n is one less than the number of panes. The method returns the name component widget.

pane(name)
Return the Tkinter.Frame pane widget for the pane specified by name, where name is either an integer, specifying the index of the pane, or a string, specifying the name of the pane.

panes()
Return a list of the names of the panes, in display order.

setnaturalsize()

Example

The image at the top of this manual is a snapshot of the window (or part of the window) produced by the following code.

class Demo:
    def __init__(self, parent):
        self.paneCount = 0

        # Create a main PanedWidget with top and bottom panes.
        pane = Pmw.PanedWidget(parent, hull_width=400, hull_height=300)
        pane.add('top', min=100)
        pane.add('bottom', min=100)

        # Create three panes in the top pane.
        topPane = Pmw.PanedWidget(pane.pane('top'), orient='horizontal',
            hull_width=0, hull_height=0)
        for num in range(4):
            if num == 1:
                name = 'Fixed\nsize'
                topPane.add(name, min = .2, max = .2)
            else:
                name = 'Pane\n' + str(num)
                topPane.add(name, min = .1, size = .25)
            button = Tkinter.Button(topPane.pane(name), text = name)
            button.pack(expand = 1)

        topPane.pack(expand = 1, fill='both')

        # Create a "pane factory" in the bottom pane.
        label = Tkinter.Label(pane.pane('bottom'),
                pady = 10,
                text = 'Below is a "pane factory".\n' +
                        'Drag the handle on the left\nto create new panes.')
        label.pack()
        self.bottomPane = Pmw.PanedWidget(pane.pane('bottom'),
                orient='horizontal',
                command = self.resize,
                hull_borderwidth = 1,
                hull_relief = 'raised',
                hull_width=0, hull_height=0
                )
        self.bottomPane.add('starter', size = 0.0)
        self.bottomPane.add('main')
        button = Tkinter.Button(self.bottomPane.pane('main'),
                text = 'Pane\n0')
        button.pack(expand = 1)
        self.bottomPane.pack(expand = 1, fill = 'both')
        pane.pack(expand = 1, fill = 'both')

    def resize(self, list):
        pane = self.bottomPane
        # Remove any panes less than 2 pixel wide.
        for i in range(len(list) - 1, 0, -1):
            if list[i] < 2:
                pane.delete(i)

        # If the user has dragged the left hand handle, create a new pane.
        if list[0] > 1:
            self.paneCount = self.paneCount + 1

            # Add a button to the new pane.
            name = pane.panes()[0]
            text = 'Pane\n' + str(self.paneCount)
            button = Tkinter.Button(pane.pane(name), text = text)
            button.pack(expand = 1)

            # Create a new starter pane.
            name = 'Pane ' + str(self.paneCount)
            pane.insert(name, size=0.0)

Home. Pmw 0.8.5 Maintainer gregm@iname.com. 9 Feb 2001