4 <meta name="description" content="Pmw - a toolkit for building high-level compound widgets in Python">
5 <meta name="content" content="python, megawidget, mega widget, compound widget, gui, tkinter">
6 <title>Pmw.PanedWidget reference manual</title>
9 <body bgcolor="#ffffff" text="#000000" link="#0000ee"
10 vlink="551a8b" alink="ff0000">
12 <h1 ALIGN="CENTER">Pmw.PanedWidget</h1>
14 <center><IMG SRC=PanedWidget.gif ALT="" WIDTH=400 HEIGHT=128></center>
16 <dt> <h3>Name</h3></dt><dd>
17 <p>Pmw.PanedWidget() -
18 frame subdivided into several resizable panes
23 <dt> <h3>Inherits</h3></dt><dd>
24 <a href="MegaWidget.html">Pmw.MegaWidget</a><br>
26 <dt> <h3>Description</h3></dt><dd>
28 A paned widget is a container megawidget which manages a number of
29 resizable frames, known as panes. Each pane may act as the container for
30 other widgets. The user may interactively resize the panes by
31 dragging a small rectangle (the handle) or the line between the
32 panes (the separator). The panes may be arranged horizontally or
33 vertically. Each pane may have maximum and minimum limits of its
40 <dt> <h3>Options</h3></dt><dd>
41 Options for this megawidget and its base
42 classes are described below.<p></p>
43 <a name=option.command></a>
44 <dl><dt> <strong>command
46 Specifies a function to be called whenever the size of any of the
47 panes changes. The function is called with a single argument,
48 being a list of the sizes of the panes, in order. For <strong>vertical</strong>
49 orientation, the size is the height of the panes. For
50 <strong>horizontal</strong> orientation, the size is the width of the panes. The default is <strong>None</strong>.</p>
54 <a name=option.handlesize></a>
55 <dl><dt> <strong>handlesize
57 Initialisation option. Specifies the size in pixels of the square handle which appears on
58 the lines separating the panes. The default is <strong>8</strong>.</p>
62 <a name=option.orient></a>
63 <dl><dt> <strong>orient
65 Initialisation option. Specifies the orientation of the paned widget. This may be
66 <strong>'horizontal'</strong> or <strong>'vertical'</strong>. If <strong>'vertical'</strong>, the panes are
67 stacked above and below each other, otherwise the panes are laid
68 out side by side. The default is <strong>'vertical'</strong>.</p>
72 <a name=option.separatorrelief></a>
73 <dl><dt> <strong>separatorrelief
75 Initialisation option. Specifies the relief of the lines separating the panes. The default is <strong>'sunken'</strong>.</p>
79 <a name=option.separatorthickness></a>
80 <dl><dt> <strong>separatorthickness
82 Initialisation option. Specifies the thickness of the lines separating the panes. The default is <strong>2</strong>.</p>
87 <dt> <h3>Pane options</h3></dt><dd>
89 Each pane has the following options. These may be set when
90 creating or configuring a pane. The value of each option may
91 be an integer, which specifies a pane size in pixels, or a
92 real number between 0.0 and 1.0, which specifies a pane size
93 proportional to the size of the entire paned widget.</p>
95 <dl><dt><strong>size</strong></dt><dd>Specifies the initial size of the pane. The default is <strong>0</strong>.<p></p>
98 <dt><strong>min</strong></dt><dd>Specifies the minimum size of the pane. The default is <strong>0</strong>.<p></p>
101 <dt><strong>max</strong></dt><dd>Specifies the maximum size of the pane. The default is a
102 very large number.<p></p>
109 <dt> <h3>Components</h3></dt><dd>
110 Components created by this megawidget and its base
111 classes are described below.<p></p>
112 <a name=component.hull></a>
113 <dl><dt> <strong>hull
115 This acts as the body for the entire megawidget. Other components
116 are created as children of the hull to further specialise this
117 class. By default, this component is a Tkinter.Frame.</p>
122 <dt> <h3>Dynamic components</h3></dt><dd>
124 Frame, separator and handle components are created dynamically
125 by the <code>add()</code> and <code>insert()</code> methods. The components are of type
126 Tkinter.Frame and are created with component groups of
127 <strong>Frame</strong>, <strong>Separator</strong> and <strong>Handle</strong> respectively.</p>
134 <dt> <h3>Methods</h3></dt><dd>
135 Only methods specific to this megawidget are described below.
136 For a description of its inherited methods, see the
137 manual for its base class
138 <strong><a href="MegaWidget.html#methods">Pmw.MegaWidget</a></strong>.
140 <a name=method.add></a>
141 <dl><dt> <strong>add</strong>(<em>name</em>, **<em>kw</em>)</dt><dd>
142 Add a pane to the end of the paned widget as a component named
143 <em>name</em>. This is equivalent to calling <code>insert()</code> with <em>before</em>
144 set to the current number of panes. The method returns the <em>name</em>
145 component widget.</p>
149 <a name=method.configurepane></a>
150 <dl><dt> <strong>configurepane</strong>(<em>name</em>, **<em>kw</em>)</dt><dd>
151 Configure the pane specified by <em>name</em>, where <em>name</em> is either an
152 integer, specifying the index of the pane, or a string, specifying
153 the name of the pane. The keyword arguments specify the new
154 values for the options for the pane. These options are described
155 in the <strong>Pane options</strong> section.</p>
159 <a name=method.delete></a>
160 <dl><dt> <strong>delete</strong>(<em>name</em>)</dt><dd>
161 Delete the pane specified by <em>name</em>, where <em>name</em> is either an
162 integer, specifying the index of the pane, or a string, specifying
163 the name of the pane.</p>
164 <p> If the pane deleted was not the only pane in the paned widget,
165 also delete the separator and handle components named
166 <strong>separator</strong>-<em>n</em> and <strong>handle</strong>-<em>n</em>, where <em>n</em> is the number of
172 <a name=method.insert></a>
173 <dl><dt> <strong>insert</strong>(<em>name</em>, <em>before</em> = <strong>0</strong>, **<em>kw</em>)</dt><dd>
174 Add a pane to the paned widget as a component named <em>name</em>. The
175 pane is added just before the pane specified by <em>before</em>, where
176 <em>before</em> may be either an integer, specifying the index of the
177 pane, or a string, specifying the name of the pane. The keyword
178 arguments specify the initial values for the options for the new
179 pane. These options are described in the <strong>Pane options</strong> section.
180 To add a pane to the end of the paned widget, use <code>add()</code>.</p>
181 <p> The new pane is created as a Tkinter.Frame component named <em>name</em>.
182 If this is not the only pane, a separator and handle are also
183 created as components named <strong>separator</strong>-<em>n</em> and <strong>handle</strong>-<em>n</em>,
184 where <em>n</em> is one less than the number of panes. The method
185 returns the <em>name</em> component widget.</p>
190 <a name=method.move></a>
191 <dl><dt> <strong>move</strong>(<em>name</em>, <em>newPos</em>, <em>newPosOffset</em> = <strong>0</strong>)</dt><dd>
192 Move the pane specified by <em>name</em> to the new position specified by
193 <em>newPos</em>. The first two arguments may be either an integer,
194 specifying the index of the pane, or a string, specifying the name
195 of the pane. If <em>newPosOffset</em> is specified, it is added to the
196 <em>newPos</em> index. For example, to move a horizontal pane one pane
197 to the left, specify the name or index of the pane for both <em>name</em>
198 and <em>newPos</em> and specify <strong>-1</strong> for <em>newPosOffset</em>.</p>
202 <a name=method.pane></a>
203 <dl><dt> <strong>pane</strong>(<em>name</em>)</dt><dd>
204 Return the Tkinter.Frame pane widget for the pane specified by
205 <em>name</em>, where <em>name</em> is either an integer, specifying the index of
206 the pane, or a string, specifying the name of the pane.</p>
210 <a name=method.panes></a>
211 <dl><dt> <strong>panes</strong>()</dt><dd>
212 Return a list of the names of the panes, in display order.</p>
216 <a name=method.setnaturalsize></a>
217 <dl><dt> <strong>setnaturalsize</strong>()</dt><dd>
218 If oriented horizontally, set the width of the paned widget to the
219 sum of the requested widths of all panes and set the height to the
220 maximum requested height of all panes.</p>
221 <p> If oriented vertically, set the height of the paned widget to the
222 sum of the requested heights of all panes and set the width to the
223 maximum requested width of all panes.</p>
228 <a name=method.updatelayout></a>
229 <dl><dt> <strong>updatelayout</strong>()</dt><dd>
230 Recalculate size and position of panes. This method must be
231 called after adding or deleting one or more panes. However it
232 does not need to be called when panes are first added to a newly
233 created paned widget, before it has been displayed.</p>
238 <dt> <h3>Example</h3></dt><dd>
239 The image at the top of this manual is a snapshot
240 of the window (or part of the window) produced
241 by the following code.<p></p>
244 def __init__(self, parent):
246 # Create a main PanedWidget with a few panes.
247 self.pw = Pmw.PanedWidget(parent,
249 hull_borderwidth = 1,
250 hull_relief = 'sunken',
253 for self.numPanes in range(4):
254 if self.numPanes == 1:
256 pane = self.pw.add(name, min = .1, max = .1)
258 name = 'Pane ' + str(self.numPanes)
259 pane = self.pw.add(name, min = .1, size = .25)
260 label = Tkinter.Label(pane, text = name)
261 label.pack(side = 'left', expand = 1)
262 button = Tkinter.Button(pane, text = 'Delete',
263 command = lambda s=self, n=name: s.deletePane(n))
264 button.pack(side = 'left', expand = 1)
265 # TODO: add buttons to invoke self.moveOneUp and self.moveOneUp.
267 self.pw.pack(expand = 1, fill='both')
269 buttonBox = Pmw.ButtonBox(parent)
270 buttonBox.pack(fill = 'x')
271 buttonBox.add('Add pane', command = self.addPane)
272 buttonBox.add('Move pane', command = self.move)
278 numPanes = len(self.pw.panes())
280 print 'No panes to move!'
283 if self.moveSrc >= numPanes:
284 self.moveSrc = numPanes - 1
285 if self.moveNewPos >= numPanes:
286 self.moveNewPos = numPanes - 1
287 print 'Moving pane', self.moveSrc, 'to new position', self.moveNewPos
288 self.pw.move(self.moveSrc, self.moveNewPos)
290 self.moveSrc, self.moveNewPos = self.moveNewPos, self.moveSrc
292 if self.moveNewPos == numPanes - 1:
294 if self.moveSrc == numPanes - 1:
297 self.moveSrc = self.moveSrc + 1
299 self.moveNewPos = self.moveNewPos + 1
300 self.moveBack = not self.moveBack
303 self.numPanes = self.numPanes + 1
304 name = 'Pane ' + str(self.numPanes)
306 pane = self.pw.add(name, min = .1, size = .25)
307 label = Tkinter.Label(pane, text = name)
308 label.pack(side = 'left', expand = 1)
309 button = Tkinter.Button(pane, text = 'Delete',
310 command = lambda s=self, n=name: s.deletePane(n))
311 button.pack(side = 'left', expand = 1)
312 self.pw.updatelayout()
314 def deletePane(self, name):
315 print 'Deleting', name
317 self.pw.updatelayout()
319 def moveOneUp(self, name):
320 self.pw.move(name, name, -1)
322 def moveOneDown(self, name):
323 self.pw.move(name, name, 1)
329 <center><P ALIGN="CENTER">
330 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
335 <center><P ALIGN="CENTER">
338 - <a href="index.html">Home</a>
339 <br>Manual page last reviewed: 14 April 2001