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.MessageDialog reference manual</title>
9 <body bgcolor="#ffffff" text="#000000" link="#0000ee"
10 vlink="551a8b" alink="ff0000">
12 <h1 ALIGN="CENTER">Pmw.MessageDialog</h1>
14 <center><IMG SRC=MessageDialog.gif ALT="" WIDTH=309 HEIGHT=220></center>
16 <dt> <h3>Name</h3></dt><dd>
17 <p>Pmw.MessageDialog() -
18 a dialog displaying a text message and an icon
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 message dialog is a dialog window which displays a simple
29 message to the user along with one or more buttons to press.</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 text message and icon. 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 text message and icon. 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.iconmargin></a>
111 <dl><dt> <strong>iconmargin
113 Initialisation option. The padding between the text message and icon. The default is <strong>20</strong>.</p>
117 <a name=option.iconpos></a>
118 <dl><dt> <strong>iconpos
120 Initialisation option. Specifies on which side of the text message to place the icon.
121 Must be one of <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> or <strong>'w'</strong>. The default is <strong>None</strong>.</p>
125 <a name=option.master></a>
126 <dl><dt> <strong>master
128 This is used by the <code>activate()</code> method to control whether the
129 window is made <em>transient</em> during modal dialogs. See the
130 <code>activate()</code> method. The default is <strong>'parent'</strong>.</p>
134 <a name=option.separatorwidth></a>
135 <dl><dt> <strong>separatorwidth
137 Initialisation option. If this is greater than <strong>0</strong>, a separator line with the specified
138 width will be created between the button box and the child site,
139 as a component named <strong>separator</strong>. Since the default border of the
140 button box and child site is <strong>raised</strong>, this option does not
141 usually need to be set for there to be a visual separation between
142 the button box and child site. The default is <strong>0</strong>.</p>
146 <a name=option.title></a>
147 <dl><dt> <strong>title
149 This is the title that the window manager displays in the title
150 bar of the window. The default is <strong>None</strong>.</p>
155 <dt> <h3>Components</h3></dt><dd>
156 Components created by this megawidget and its base
157 classes are described below.<p></p>
158 <a name=component.buttonbox></a>
159 <dl><dt> <strong>buttonbox
161 This is the button box containing the buttons for the dialog. By
162 default it is created with the options
163 <code>(hull_borderwidth = 1, hull_relief = 'raised')</code>. By default, this component is a <a href="ButtonBox.html">Pmw.ButtonBox</a>.</p>
167 <a name=component.dialogchildsite></a>
168 <dl><dt> <strong>dialogchildsite
170 This is the child site for the dialog, which may be used to
171 specialise the megawidget by creating other widgets within it. By
172 default it is created with the options
173 <code>(borderwidth = 1, relief = 'raised')</code>. By default, this component is a Tkinter.Frame.</p>
177 <a name=component.hull></a>
178 <dl><dt> <strong>hull
180 This acts as the body for the entire megawidget. Other components
181 are created as children of the hull to further specialise this
182 class. By default, this component is a Tkinter.Toplevel.</p>
186 <a name=component.icon></a>
187 <dl><dt> <strong>icon
189 If the <strong>iconpos</strong> option is not <strong>None</strong>, this component is created
190 to contain the icon label for the dialog. To display a bitmap as
191 an icon, set the <strong>icon_bitmap</strong> component option to any of the
192 forms acceptable to Tk, such as <strong>'warning'</strong> or <strong>'error'</strong>. By default, this component is a Tkinter.Label.</p>
196 <a name=component.message></a>
197 <dl><dt> <strong>message
199 The label to contain the text message for the dialog. To set
200 the text, use the <strong>message_text</strong> component option. By default, this component is a Tkinter.Label.</p>
204 <a name=component.separator></a>
205 <dl><dt> <strong>separator
207 If the <strong>separatorwidth</strong> initialisation option is non-zero, the
208 <strong>separator</strong> component is the line dividing the area between the
209 button box and the child site. By default, this component is a Tkinter.Frame.</p>
215 <dt> <h3>Methods</h3></dt><dd>
216 This megawidget has no methods of its own.
217 For a description of its inherited methods, see the
218 manual for its base class
219 <strong><a href="Dialog.html#methods">Pmw.Dialog</a></strong>.
222 <dt> <h3>Example</h3></dt><dd>
223 The image at the top of this manual is a snapshot
224 of the window (or part of the window) produced
225 by the following code.<p></p>
228 def __init__(self, parent):
232 self.dialog1 = Pmw.MessageDialog(parent,
233 title = 'Simple message dialog',
235 message_text = 'A simple message dialog\nwith no callback.')
236 self.dialog1.iconname('Simple message dialog')
237 self.dialog1.withdraw()
240 self.dialog2 = Pmw.MessageDialog(parent,
241 title = 'Bell ringing dialog',
242 message_text = 'This message dialog\nwill ring the bell ' +
243 'when\nyou click on the buttons.',
245 icon_bitmap = 'error',
246 command = self.execute2,
247 buttons = ('One', 'Two', 'Three', 'Close'))
248 self.dialog2.iconname('Bell ringing dialog')
249 self.dialog2.withdraw()
252 self.dialog3 = Pmw.MessageDialog(parent,
253 title = 'Vertical button dialog',
254 message_text = 'This message dialog\nhas the buttons on the\n' +
258 icon_bitmap = 'warning',
259 buttons = ('Goodbye', 'Au revoir', 'Sayonara', 'Close'),
260 defaultbutton = 'Close')
261 self.dialog3.iconname('Vertical button dialog')
262 self.dialog3.withdraw()
264 # Create some buttons to launch the dialogs.
265 w = Tkinter.Button(parent, text = 'Simple dialog',
266 command = lambda self = self:
267 self.dialog1.activate(geometry = 'first+100+100'))
268 w.pack(padx = 8, pady = 8)
270 w = Tkinter.Button(parent, text = 'Bell ringing dialog',
271 command = self.dialog2.activate)
272 w.pack(padx = 8, pady = 8)
274 w = Tkinter.Button(parent, text = 'Vertical buttons',
275 command = self.dialog3.activate)
276 w.pack(padx = 8, pady = 8)
278 w = Tkinter.Button(parent, text = 'On the fly dialog',
279 command = self._createOnTheFly)
280 w.pack(padx = 8, pady = 8)
282 def execute2(self, result):
283 print 'You clicked on', result
285 self.dialog2.deactivate(result)
286 elif result == 'Close':
287 self.dialog2.deactivate(result)
289 for count in range({'One': 1, 'Two': 2, 'Three': 3}[result]):
291 self.dialog2.after(200)
294 def _createOnTheFly(self):
295 dialog = Pmw.MessageDialog(self.parent,
296 title = 'On the fly dialog',
298 buttons = ('OK', 'Apply', 'Cancel', 'Help'),
299 message_text = 'This dialog was created when you clicked ' +
301 dialog.iconname('Simple message dialog')
302 result = dialog.activate()
304 print 'You selected', result
310 <center><P ALIGN="CENTER">
311 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
316 <center><P ALIGN="CENTER">
319 - <a href="index.html">Home</a>
320 <br>Manual page last reviewed: 18 May 2002