Pmw.MessageDialog

Name

Pmw.MessageDialog() - a dialog displaying a text message and an icon

Inherits

Pmw.Dialog

Description

A message dialog is a dialog window which displays a simple message to the user along with one or more buttons to press.

Options

Options for this megawidget and its base classes are described below.

activatecommand
If this is callable, it will be called whenever the megawidget is activated by a call to activate(). The default is None.

borderx
Initialisation option. The padding to the left and right of the text message and icon. The default is 20.

bordery
Initialisation option. The padding above and below the text message and icon. The default is 20.

buttonboxpos
Initialisation option. Specifies on which side of the dialog window to place the button box. Must be one of 'n', 's', 'e' or 'w'. The default is 's'.

buttons
This must be a tuple or a list and specifies the names on the buttons in the button box. The default is ('OK',).

command
Specifies a function to call whenever a button in the button box is invoked or the window is deleted by the window manager. The function is called with a single argument, which is the name of the button which was invoked, or None if the window was deleted by the window manager.

If the value of command is not callable, the default behaviour is to deactivate the window if it is active, or withdraw the window if it is not active. If it is deactivated, deactivate() is called with the button name or None as described above. The default is None.

deactivatecommand
If this is callable, it will be called whenever the megawidget is deactivated by a call to deactivate(). The default is None.

defaultbutton
Specifies the default button in the button box. If the <Return> key is hit when the dialog has focus, the default button will be invoked. If defaultbutton is None, there will be no default button and hitting the <Return> key will have no effect. The default is None.

iconmargin
Initialisation option. The padding between the text message and icon. The default is 20.

iconpos
Initialisation option. Specifies on which side of the text message to place the icon. Must be one of 'n', 's', 'e' or 'w'. The default is None.

master
This is used by the activate() method to control whether the window is made transient during modal dialogs. See the activate() method. The default is 'parent'.

separatorwidth
Initialisation option. If this is greater than 0, a separator line with the specified width will be created between the button box and the child site, as a component named separator. Since the default border of the button box and child site is raised, this option does not usually need to be set for there to be a visual separation between the button box and child site. The default is 0.

title
This is the title that the window manager displays in the title bar of the window. The default is None.

Components

Components created by this megawidget and its base classes are described below.

buttonbox
This is the button box containing the buttons for the dialog. By default it is created with the options (hull_borderwidth = 1, hull_relief = 'raised'). By default, this component is a Pmw.ButtonBox.

dialogchildsite
This is the child site for the dialog, which may be used to specialise the megawidget by creating other widgets within it. By default it is created with the options (borderwidth = 1, relief = 'raised'). By default, this component is a Tkinter.Frame.

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.Toplevel.

icon
If the iconpos option is not None, this component is created to contain the icon label for the dialog. To display a bitmap as an icon, set the icon_bitmap component option to any of the forms acceptable to Tk, such as 'warning' or 'error'. By default, this component is a Tkinter.Label.

message
The label to contain the text message for the dialog. To set the text, use the message_text component option. By default, this component is a Tkinter.Label.

separator
If the separatorwidth initialisation option is non-zero, the separator component is the line dividing the area between the button box and the child site. By default, this component is a Tkinter.Frame.

Methods

This megawidget has no methods of its own. For a description of its inherited methods, see the manual for its base class Pmw.Dialog.

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):
        self.parent = parent

        # Create dialog 1.
        self.dialog1 = Pmw.MessageDialog(parent,
            title = 'Simple message dialog',
            defaultbutton = 0,
            message_text = 'A simple message dialog\nwith no callback.')
        self.dialog1.iconname('Simple message dialog')
        self.dialog1.withdraw()

        # Create dialog 2.
        self.dialog2 = Pmw.MessageDialog(parent,
            title = 'Bell ringing dialog',
            message_text = 'This message dialog\nwill ring the bell ' +
                'when\nyou click on the buttons.',
            iconpos = 'w',
            icon_bitmap = 'error',
            command = self.execute2,
            buttons = ('One', 'Two', 'Three', 'Close'))
        self.dialog2.iconname('Bell ringing dialog')
        self.dialog2.withdraw()

        # Create dialog 3.
        self.dialog3 = Pmw.MessageDialog(parent,
            title = 'Vertical button dialog',
            message_text = 'This message dialog\nhas the buttons on the\n' +
                'right hand side.',
            buttonboxpos = 'e',
            iconpos = 'n',
            icon_bitmap = 'warning',
            buttons = ('Goodbye', 'Au revoir', 'Sayonara', 'Close'),
            defaultbutton = 'Close')
        self.dialog3.iconname('Vertical button dialog')
        self.dialog3.withdraw()

        # Create some buttons to launch the dialogs.
        w = Tkinter.Button(parent, text = 'Simple dialog',
                command = lambda self = self:
                        self.dialog1.activate(geometry = 'first+100+100'))
        w.pack(padx = 8, pady = 8)

        w = Tkinter.Button(parent, text = 'Bell ringing dialog',
                command = self.dialog2.activate)
        w.pack(padx = 8, pady = 8)

        w = Tkinter.Button(parent, text = 'Vertical buttons',
                command = self.dialog3.activate)
        w.pack(padx = 8, pady = 8)

        w = Tkinter.Button(parent, text = 'On the fly dialog',
                command = self._createOnTheFly)
        w.pack(padx = 8, pady = 8)

    def execute2(self, result):
        print 'You clicked on', result
        if result is None:
            self.dialog2.deactivate(result)
        elif result == 'Close':
            self.dialog2.deactivate(result)
        else:
            for count in range({'One': 1, 'Two': 2, 'Three': 3}[result]):
                if count != 0:
                    self.dialog2.after(200)
                self.dialog2.bell()

    def _createOnTheFly(self):
        dialog = Pmw.MessageDialog(self.parent,
            title = 'On the fly dialog',
            defaultbutton = 0,
            buttons = ('OK', 'Apply', 'Cancel', 'Help'),
            message_text = 'This dialog was created when you clicked ' +
                'on the button.')
        dialog.iconname('Simple message dialog')
        result = dialog.activate()

        print 'You selected', result

Pmw 1.2 - 5 Aug 2003 - Home
Manual page last reviewed: 18 May 2002