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.CounterDialog reference manual</title>
9 <body bgcolor="#ffffff" text="#000000" link="#0000ee"
10 vlink="551a8b" alink="ff0000">
12 <h1 ALIGN="CENTER">Pmw.CounterDialog</h1>
14 <center><IMG SRC=CounterDialog.gif ALT="" WIDTH=268 HEIGHT=198></center>
16 <dt> <h3>Name</h3></dt><dd>
17 <p>Pmw.CounterDialog() -
18 selection dialog displaying a counter
23 <dt> <h3>Inherits</h3></dt><dd>
24 <a href="Dialog.html">Pmw.Dialog</a><br>
26 <dt> <h3>Description</h3></dt><dd>
28 A counter dialog is a dialog window which displays a counter
29 which can be used to prompt the user for a value.</p>
35 <dt> <h3>Options</h3></dt><dd>
36 Options for this megawidget and its base
37 classes are described below.<p></p>
38 <a name=option.activatecommand></a>
39 <dl><dt> <strong>activatecommand
41 If this is callable, it will be called whenever the megawidget is
42 activated by a call to <code>activate()</code>. The default is <strong>None</strong>.</p>
46 <a name=option.borderx></a>
47 <dl><dt> <strong>borderx
49 Initialisation option. The padding to the left and right of the counter. The default is <strong>20</strong>.</p>
53 <a name=option.bordery></a>
54 <dl><dt> <strong>bordery
56 Initialisation option. The padding above and below the counter. The default is <strong>20</strong>.</p>
60 <a name=option.buttonboxpos></a>
61 <dl><dt> <strong>buttonboxpos
63 Initialisation option. Specifies on which side of the dialog window to place the button
64 box. Must be one of <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> or <strong>'w'</strong>. The default is <strong>'s'</strong>.</p>
68 <a name=option.buttons></a>
69 <dl><dt> <strong>buttons
71 This must be a tuple or a list and specifies the names on the
72 buttons in the button box. The default is <strong>('OK',)</strong>.</p>
76 <a name=option.command></a>
77 <dl><dt> <strong>command
79 Specifies a function to call whenever a button in the button box
80 is invoked or the window is deleted by the window manager. The
81 function is called with a single argument, which is the name of
82 the button which was invoked, or <strong>None</strong> if the window was deleted
83 by the window manager.</p>
84 <p> If the value of <strong>command</strong> is not callable, the default behaviour
85 is to deactivate the window if it is active, or withdraw the
86 window if it is not active. If it is deactivated, <code>deactivate()</code>
87 is called with the button name or <strong>None</strong> as described above. The default is <strong>None</strong>.</p>
92 <a name=option.deactivatecommand></a>
93 <dl><dt> <strong>deactivatecommand
95 If this is callable, it will be called whenever the megawidget is
96 deactivated by a call to <code>deactivate()</code>. The default is <strong>None</strong>.</p>
100 <a name=option.defaultbutton></a>
101 <dl><dt> <strong>defaultbutton
103 Specifies the default button in the button box. If the <strong><Return></strong>
104 key is hit when the dialog has focus, the default button will be
105 invoked. If <strong>defaultbutton</strong> is <strong>None</strong>, there will be no default
106 button and hitting the <strong><Return></strong> key will have no effect. The default is <strong>None</strong>.</p>
110 <a name=option.master></a>
111 <dl><dt> <strong>master
113 This is used by the <code>activate()</code> method to control whether the
114 window is made <em>transient</em> during modal dialogs. See the
115 <code>activate()</code> method. The default is <strong>'parent'</strong>.</p>
119 <a name=option.separatorwidth></a>
120 <dl><dt> <strong>separatorwidth
122 Initialisation option. If this is greater than <strong>0</strong>, a separator line with the specified
123 width will be created between the button box and the child site,
124 as a component named <strong>separator</strong>. Since the default border of the
125 button box and child site is <strong>raised</strong>, this option does not
126 usually need to be set for there to be a visual separation between
127 the button box and child site. The default is <strong>0</strong>.</p>
131 <a name=option.title></a>
132 <dl><dt> <strong>title
134 This is the title that the window manager displays in the title
135 bar of the window. The default is <strong>None</strong>.</p>
140 <dt> <h3>Components</h3></dt><dd>
141 Components created by this megawidget and its base
142 classes are described below.<p></p>
143 <a name=component.buttonbox></a>
144 <dl><dt> <strong>buttonbox
146 This is the button box containing the buttons for the dialog. By
147 default it is created with the options
148 <code>(hull_borderwidth = 1, hull_relief = 'raised')</code>. By default, this component is a <a href="ButtonBox.html">Pmw.ButtonBox</a>.</p>
152 <a name=component.counter></a>
153 <dl><dt> <strong>counter
155 The counter for the user to enter a value. By default, this component is a <a href="Counter.html">Pmw.Counter</a>.</p>
159 <a name=component.dialogchildsite></a>
160 <dl><dt> <strong>dialogchildsite
162 This is the child site for the dialog, which may be used to
163 specialise the megawidget by creating other widgets within it. By
164 default it is created with the options
165 <code>(borderwidth = 1, relief = 'raised')</code>. By default, this component is a Tkinter.Frame.</p>
169 <a name=component.hull></a>
170 <dl><dt> <strong>hull
172 This acts as the body for the entire megawidget. Other components
173 are created as children of the hull to further specialise this
174 class. By default, this component is a Tkinter.Toplevel.</p>
178 <a name=component.separator></a>
179 <dl><dt> <strong>separator
181 If the <strong>separatorwidth</strong> initialisation option is non-zero, the
182 <strong>separator</strong> component is the line dividing the area between the
183 button box and the child site. By default, this component is a Tkinter.Frame.</p>
188 <dt> <h3>Component aliases</h3></dt><dd>
189 Sub-components of components of this megawidget
190 may be accessed via the following aliases.<p></p>
191 <dl><dt> <strong>entry
193 Alias for <strong>counter_entryfield_entry</strong>.
195 <dl><dt> <strong>entryfield
197 Alias for <strong>counter_entryfield</strong>.
199 <dl><dt> <strong>label
201 Alias for <strong>counter_label</strong>.
205 <dt> <h3>Methods</h3></dt><dd>
206 Only methods specific to this megawidget are described below.
207 For a description of its inherited methods, see the
208 manual for its base class
209 <strong><a href="Dialog.html#methods">Pmw.Dialog</a></strong>.
210 In addition, methods from the
211 <strong><a href="Counter.html#methods">Pmw.Counter</a></strong> class
212 are forwarded by this megawidget to the
213 <strong>counter</strong> component.
215 <a name=method.deleteentry></a>
216 <dl><dt> <strong>deleteentry</strong>(<em>first</em>, <em>last</em> = <strong>None</strong>)</dt><dd>
217 Delete text from the counter's entry widget. An alias for
218 <code>component('entry').delete()</code>.</p>
222 <a name=method.indexentry></a>
223 <dl><dt> <strong>indexentry</strong>(<em>index</em>)</dt><dd>
224 An alias for <code>component('entry').index()</code>.</p>
228 <a name=method.insertentry></a>
229 <dl><dt> <strong>insertentry</strong>(<em>index</em>, <em>text</em>)</dt><dd>
230 Insert text into the counter's entry widget. An alias for
231 <code>component('entry').insert()</code>.</p>
236 <dt> <h3>Example</h3></dt><dd>
237 The image at the top of this manual is a snapshot
238 of the window (or part of the window) produced
239 by the following code.<p></p>
242 def __init__(self, parent):
243 # Create the dialog to prompt for the number of times to ring the bell.
244 self.dialog = Pmw.CounterDialog(parent,
245 label_text = 'Enter the number of times to\n' + \
246 'sound the bell (1 to 5)\n',
247 counter_labelpos = 'n',
248 entryfield_value = 2,
249 counter_datatype = 'numeric',
250 entryfield_validate =
251 {'validator' : 'numeric', 'min' : 1, 'max' : 5},
252 buttons = ('OK', 'Cancel'),
253 defaultbutton = 'OK',
254 title = 'Bell ringing',
255 command = self.execute)
256 self.dialog.withdraw()
258 # Create button to launch the dialog.
259 w = Tkinter.Button(parent, text = 'Show counter dialog',
260 command = self.dialog.activate)
261 w.pack(padx = 8, pady = 8)
263 def execute(self, result):
264 if result is None or result == 'Cancel':
265 print 'Bell ringing cancelled'
266 self.dialog.deactivate()
268 count = self.dialog.get()
269 if not self.dialog.valid():
270 print 'Invalid entry: "' + count + '"'
272 print 'Ringing the bell ' + count + ' times'
273 for num in range(string.atoi(count)):
275 self.dialog.after(200)
277 self.dialog.deactivate()
283 <center><P ALIGN="CENTER">
284 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
289 <center><P ALIGN="CENTER">
292 - <a href="index.html">Home</a>
293 <br>Manual page last reviewed: 18 May 2002