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.ScrolledText reference manual</title>
9 <body bgcolor="#ffffff" text="#000000" link="#0000ee"
10 vlink="551a8b" alink="ff0000">
12 <h1 ALIGN="CENTER">Pmw.ScrolledText</h1>
14 <center><IMG SRC=ScrolledText.gif ALT="" WIDTH=409 HEIGHT=310></center>
16 <dt> <h3>Name</h3></dt><dd>
17 <p>Pmw.ScrolledText() -
18 text widget with optional scrollbars
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 scrolled text consists of a standard text widget with optional
29 scrollbars which can be used to scroll the text. The
30 scrollbars can be <em>dynamic</em>, which means that a scrollbar will
31 only be displayed if it is necessary. That is, if the text widget
32 does not contain enough text (either horizontally or vertically),
33 the scrollbar will be automatically hidden. If it is displayed,
34 the horizontal scrollbar is under the text widget. Similarly, if
35 it is displayed, the vertical scrollbar is to the right of the
38 <p> Row and column headers may also be displayed, which scroll in sync
39 with the text widget and may be useful when displaying tabular
40 data. To assist in ensuring that columns line up when using a
41 column header, a fixed width font should be used.</p>
47 <dt> <h3>Options</h3></dt><dd>
48 Options for this megawidget and its base
49 classes are described below.<p></p>
50 <a name=option.borderframe></a>
51 <dl><dt> <strong>borderframe
53 Initialisation option. If true, the <strong>borderframe</strong> component will be created. The default is <strong>0</strong>.</p>
57 <a name=option.columnheader></a>
58 <dl><dt> <strong>columnheader
60 Initialisation option. If true, the <strong>columnheader</strong> component will be created. The default is <strong>0</strong>.</p>
64 <a name=option.hscrollmode></a>
65 <dl><dt> <strong>hscrollmode
67 The horizontal scroll mode. If <strong>'none'</strong>, the horizontal scrollbar
68 will never be displayed. If <strong>'static'</strong>, the scrollbar will always
69 be displayed. If <strong>'dynamic'</strong>, the scrollbar will be displayed
70 only if necessary. The default is <strong>'dynamic'</strong>.</p>
74 <a name=option.labelmargin></a>
75 <dl><dt> <strong>labelmargin
77 Initialisation option. If the <strong>labelpos</strong> option is not <strong>None</strong>, this specifies the
78 distance between the <strong>label</strong> component and the rest of the
79 megawidget. The default is <strong>0</strong>.</p>
83 <a name=option.labelpos></a>
84 <dl><dt> <strong>labelpos
86 Initialisation option. Specifies where to place the <strong>label</strong> component. If not
87 <strong>None</strong>, it should be a concatenation of one or two of the
88 letters <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> and <strong>'w'</strong>. The first letter
89 specifies on which side of the megawidget to place the label.
90 If a second letter is specified, it indicates where on that
91 side to place the label. For example, if <strong>labelpos</strong> is <strong>'w'</strong>,
92 the label is placed in the center of the left hand side; if
93 it is <strong>'wn'</strong>, the label is placed at the top of the left
94 hand side; if it is <strong>'ws'</strong>, the label is placed at the
95 bottom of the left hand side.</p>
96 <p> If <strong>None</strong>, a label component is not created. The default is <strong>None</strong>.</p>
101 <a name=option.rowcolumnheader></a>
102 <dl><dt> <strong>rowcolumnheader
104 Initialisation option. If true, the <strong>rowcolumnheader</strong> component will be created. The default is <strong>0</strong>.</p>
108 <a name=option.rowheader></a>
109 <dl><dt> <strong>rowheader
111 Initialisation option. If true, the <strong>rowheader</strong> component will be created. The default is <strong>0</strong>.</p>
115 <a name=option.scrollmargin></a>
116 <dl><dt> <strong>scrollmargin
118 Initialisation option. The distance between the scrollbars and the text widget. The default is <strong>2</strong>.</p>
122 <a name=option.usehullsize></a>
123 <dl><dt> <strong>usehullsize
125 Initialisation option. If true, the size of the megawidget is determined solely by the
126 width and height options of the <strong>hull</strong> component.</p>
127 <p> Otherwise, the size of the megawidget is determined by the width
128 and height of the <strong>text</strong> component, along with the size and/or
129 existence of the other components, such as the label, the
130 scrollbars and the scrollmargin option. All these affect the
131 overall size of the megawidget. The default is <strong>0</strong>.</p>
136 <a name=option.vscrollmode></a>
137 <dl><dt> <strong>vscrollmode
139 The vertical scroll mode. If <strong>'none'</strong>, the vertical scrollbar
140 will never be displayed. If <strong>'static'</strong>, the scrollbar will always
141 be displayed. If <strong>'dynamic'</strong>, the scrollbar will be displayed
142 only if necessary. The default is <strong>'dynamic'</strong>.</p>
147 <dt> <h3>Components</h3></dt><dd>
148 Components created by this megawidget and its base
149 classes are described below.<p></p>
150 <a name=component.borderframe></a>
151 <dl><dt> <strong>borderframe
153 A frame widget which snuggly fits around the text widget, to give
154 the appearance of a text border. It is created with a border so
155 that the text widget, which is created without a border, looks
156 like it has a border. By default, this component is a Tkinter.Frame.</p>
160 <a name=component.columnheader></a>
161 <dl><dt> <strong>columnheader
163 A text widget with a default height of 1 displayed above the main
164 text widget and which scrolls horizontally in sync with the
165 horizontal scrolling of the main text widget. By default, this component is a Tkinter.Text. Its component group is <strong>Header</strong>.</p>
169 <a name=component.horizscrollbar></a>
170 <dl><dt> <strong>horizscrollbar
172 The horizontal scrollbar. By default, this component is a Tkinter.Scrollbar. Its component group is <strong>Scrollbar</strong>.</p>
176 <a name=component.hull></a>
177 <dl><dt> <strong>hull
179 This acts as the body for the entire megawidget. Other components
180 are created as children of the hull to further specialise this
181 class. By default, this component is a Tkinter.Frame.</p>
185 <a name=component.label></a>
186 <dl><dt> <strong>label
188 If the <strong>labelpos</strong> option is not <strong>None</strong>, this component is
189 created as a text label for the megawidget. See the
190 <strong>labelpos</strong> option for details. Note that to set, for example,
191 the <strong>text</strong> option of the label, you need to use the <strong>label_text</strong>
192 component option. By default, this component is a Tkinter.Label.</p>
196 <a name=component.rowcolumnheader></a>
197 <dl><dt> <strong>rowcolumnheader
199 A text widget displayed to the top left of the main text widget,
200 above the row header and to the left of the column header if they
201 exist. The widget is not scrolled automatically. By default, this component is a Tkinter.Text. Its component group is <strong>Header</strong>.</p>
205 <a name=component.rowheader></a>
206 <dl><dt> <strong>rowheader
208 A text widget displayed to the left of the main text widget and
209 which scrolls vertically in sync with the vertical scrolling of
210 the main text widget. By default, this component is a Tkinter.Text. Its component group is <strong>Header</strong>.</p>
214 <a name=component.text></a>
215 <dl><dt> <strong>text
217 The text widget which is scrolled by the scrollbars. If the
218 <strong>borderframe</strong> option is true, this is created with a borderwidth
219 of <strong>0</strong> to overcome a known problem with text widgets: if a widget
220 inside a text widget extends across one of the edges of the text
221 widget, then the widget obscures the border of the text widget.
222 Therefore, if the text widget has no border, then this overlapping
223 does not occur. By default, this component is a Tkinter.Text.</p>
227 <a name=component.vertscrollbar></a>
228 <dl><dt> <strong>vertscrollbar
230 The vertical scrollbar. By default, this component is a Tkinter.Scrollbar. Its component group is <strong>Scrollbar</strong>.</p>
236 <dt> <h3>Methods</h3></dt><dd>
237 Only methods specific to this megawidget are described below.
238 For a description of its inherited methods, see the
239 manual for its base class
240 <strong><a href="MegaWidget.html#methods">Pmw.MegaWidget</a></strong>.
241 In addition, methods from the
242 <strong>Tkinter.Text</strong> class
243 are forwarded by this megawidget to the
244 <strong>text</strong> component.
246 <a name=method.appendtext></a>
247 <dl><dt> <strong>appendtext</strong>(<em>text</em>)</dt><dd>
248 Add <em>text</em> to the end of the <strong>text</strong> component. Scroll to the
249 bottom of the text, but only if it was already visible before the
250 new text was added.</p>
254 <a name=method.bbox></a>
255 <dl><dt> <strong>bbox</strong>(<em>index</em>)</dt><dd>
256 This method is explicitly forwarded to the <strong>text</strong> component's
257 <code>bbox()</code> method. Without this explicit forwarding, the <code>bbox()</code>
258 method (aliased to <code>grid_bbox()</code>) of the <strong>hull</strong> would be invoked,
259 which is probably not what the programmer intended.</p>
263 <a name=method.clear></a>
264 <dl><dt> <strong>clear</strong>()</dt><dd>
265 Delete all text from the <strong>text</strong> component.</p>
269 <a name=method.exportfile></a>
270 <dl><dt> <strong>exportfile</strong>(<em>fileName</em>)</dt><dd>
271 Write the contents of the <strong>text</strong> component to the file <em>fileName</em>.</p>
275 <a name=method.get></a>
276 <dl><dt> <strong>get</strong>(<em>first</em> = <strong>None</strong>, <em>last</em> = <strong>None</strong>)</dt><dd>
277 This is the same as the <code>get()</code> method of the <strong>text</strong> component,
278 except that if <em>first</em> is <strong>None</strong> the entire
279 contents of the text widget are returned.</p>
283 <a name=method.getvalue></a>
284 <dl><dt> <strong>getvalue</strong>()</dt><dd>
285 Return the entire contents of the text widget.</p>
289 <a name=method.importfile></a>
290 <dl><dt> <strong>importfile</strong>(<em>fileName</em>, <em>where</em> = <strong>'end'</strong>)</dt><dd>
291 Read the contents of the file <em>fileName</em> and insert into the
292 <strong>text</strong> component at the position given by <em>where</em>.</p>
296 <a name=method.settext></a>
297 <dl><dt> <strong>settext</strong>(<em>text</em>)</dt><dd>
298 Same as <code>setvalue()</code> method.</p>
302 <a name=method.setvalue></a>
303 <dl><dt> <strong>setvalue</strong>(<em>text</em>)</dt><dd>
304 Replace the entire contents of the <strong>text</strong> component with <em>text</em>.</p>
309 <dt> <h3>Example</h3></dt><dd>
310 The image at the top of this manual is a snapshot
311 of the window (or part of the window) produced
312 by the following code.<p></p>
315 def __init__(self, parent):
317 # Create the ScrolledText with headers.
318 fixedFont = Pmw.logicalfont('Fixed')
319 self.st = Pmw.ScrolledText(parent,
322 label_text='ScrolledText with headers',
330 text_font = fixedFont,
331 Header_font = fixedFont,
332 Header_foreground = 'blue',
334 rowcolumnheader_width = 3,
341 self.st.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
343 funcs = 'atan cos cosh exp log log10 sin sinh sqrt tan tanh'
344 funcs = string.split(funcs)
346 # Create the header for the row headers
347 self.st.component('rowcolumnheader').insert('end', 'x')
349 # Create the column headers
351 for column in range(len(funcs)):
352 headerLine = headerLine + ('%-7s ' % (funcs[column],))
353 headerLine = headerLine[:-3]
354 self.st.component('columnheader').insert('0.0', headerLine)
356 self.st.tag_configure('yellow', background = 'yellow')
358 # Create the data rows and the row headers
361 for row in range(1, numRows):
364 for column in range(len(funcs)):
365 value = eval('math.' + funcs[column] + '(' + str(x) + ')')
366 data = str(value)[:7]
368 tag1 = '%d.%d' % (row, len(dataLine))
369 tag2 = '%d.%d' % (row, len(dataLine) + len(data))
372 data = '%-7s' % (data,)
373 dataLine = dataLine + data + ' '
374 dataLine = dataLine[:-3]
375 header = '%.1f' % (x,)
376 if row < numRows - 1:
377 dataLine = dataLine + '\n'
378 header = header + '\n'
379 self.st.insert('end', dataLine)
380 self.st.component('rowheader').insert('end', header)
381 apply(self.st.tag_add, ('yellow',) + tuple(tagList))
383 # Prevent users' modifying text and headers
385 text_state = 'disabled',
386 Header_state = 'disabled',
393 <center><P ALIGN="CENTER">
394 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
399 <center><P ALIGN="CENTER">
402 - <a href="index.html">Home</a>
403 <br>Manual page last reviewed: 30 August 1998