Pmw.PanedWidget

Name

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

Inherits

Pmw.MegaWidget

Description

A paned widget is a container megawidget which manages a number of resizable frames, known as panes. Each pane may act as the container for other widgets. The user may interactively 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. Each pane may have maximum and minimum limits of its size.

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. Specifies the size in pixels of the square handle which appears on the lines separating the panes. 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 lines separating the panes. The default is 'sunken'.

separatorthickness
Initialisation option. Specifies the thickness of the lines separating the panes. 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 this class. 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 manual for its base class Pmw.MegaWidget.

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.

move(name, newPos, newPosOffset = 0)
Move the pane specified by name to the new position specified by newPos. The first two arguments may be either an integer, specifying the index of the pane, or a string, specifying the name of the pane. If newPosOffset is specified, it is added to the newPos index. For example, to move a horizontal pane one pane to the left, specify the name or index of the pane for both name and newPos and specify -1 for newPosOffset.

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()
If oriented horizontally, set the width of the paned widget to the sum of the requested widths of all panes and set the height to the maximum requested height of all panes.

If oriented vertically, set the height of the paned widget to the sum of the requested heights of all panes and set the width to the maximum requested width of all panes.

updatelayout()
Recalculate size and position of panes. This method must be called after adding or deleting one or more panes. However it does not need to be called when panes are first added to a newly created paned widget, before it has been displayed.

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):

        # Create a main PanedWidget with a few panes.
        self.pw = Pmw.PanedWidget(parent,
                orient='vertical',
                hull_borderwidth = 1,
                hull_relief = 'sunken',
                hull_width=300,
                hull_height=400)
        for self.numPanes in range(4):
            if self.numPanes == 1:
                name = 'Fixed size'
                pane = self.pw.add(name, min = .1, max = .1)
            else:
                name = 'Pane ' + str(self.numPanes)
                pane = self.pw.add(name, min = .1, size = .25)
            label = tkinter.Label(pane, text = name)
            label.pack(side = 'left', expand = 1)
            button = tkinter.Button(pane, text = 'Delete',
                    command = lambda s=self, n=name: s.deletePane(n))
            button.pack(side = 'left', expand = 1)
            # TODO: add buttons to invoke self.moveOneUp and self.moveOneUp.

        self.pw.pack(expand = 1, fill='both')

        buttonBox = Pmw.ButtonBox(parent)
        buttonBox.pack(fill = 'x')
        buttonBox.add('Add pane', command = self.addPane)
        buttonBox.add('Move pane', command = self.move)
        self.moveSrc = 0
        self.moveNewPos = 1
        self.moveBack = 0

    def move(self):
        numPanes = len(self.pw.panes())
        if numPanes == 0:
            print('No panes to move!')
            return

        if self.moveSrc >= numPanes:
            self.moveSrc = numPanes - 1
        if self.moveNewPos >= numPanes:
            self.moveNewPos = numPanes - 1
        print('Moving pane ' + str(self.moveSrc) + ' to new position ' + str(self.moveNewPos))
        self.pw.move(self.moveSrc, self.moveNewPos)

        self.moveSrc, self.moveNewPos = self.moveNewPos, self.moveSrc
        if self.moveBack:
            if self.moveNewPos == numPanes - 1:
                self.moveNewPos = 0
                if self.moveSrc == numPanes - 1:
                    self.moveSrc = 0
                else:
                    self.moveSrc = self.moveSrc + 1
            else:
                self.moveNewPos = self.moveNewPos + 1
        self.moveBack = not self.moveBack

    def addPane(self):
        self.numPanes = self.numPanes + 1
        name = 'Pane ' + str(self.numPanes)
        print('Adding ' + name)
        pane = self.pw.add(name, min = .1, size = .25)
        label = tkinter.Label(pane, text = name)
        label.pack(side = 'left', expand = 1)
        button = tkinter.Button(pane, text = 'Delete',
                command = lambda s=self, n=name: s.deletePane(n))
        button.pack(side = 'left', expand = 1)
        self.pw.updatelayout()

    def deletePane(self, name):
        print('Deleting ' + name)
        self.pw.delete(name)
        self.pw.updatelayout()

    def moveOneUp(self, name):
        self.pw.move(name, name, -1)

    def moveOneDown(self, name):
        self.pw.move(name, name, 1)

Pmw 2.1 - 31 Dec 2020 - Home
Manual page last reviewed: 14 April 2001