Pmw.Dialog

Name

Pmw.Dialog() - toplevel window with button box

Inherits

Pmw.MegaToplevel

Description

A dialog is a toplevel window composed of a button box and a child site area. The child site area can be used to specialise the megawidget by creating other widgets within it. This can be done by using this class directly or by deriving from it.

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.

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.

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.

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

Only methods specific to this megawidget are described below. For a description of its inherited methods, see the manual for its base class Pmw.MegaToplevel.

interior()
Return the child site for the dialog. This is the same as component('dialogchildsite').

invoke(index = Pmw.DEFAULT)
Invoke the command specified by the command option as if the button specified by index had been pressed and return the result. index may have any of the forms accepted by the Pmw.ButtonBox index() method.

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):
        # Create two buttons to launch the dialog.
        w = tkinter.Button(parent, text = 'Show application modal dialog',
                command = self.showAppModal)
        w.pack(padx = 8, pady = 8)

        w = tkinter.Button(parent, text = 'Show global modal dialog',
                command = self.showGlobalModal)
        w.pack(padx = 8, pady = 8)

        w = tkinter.Button(parent, text = 'Show dialog with "no grab"',
                command = self.showDialogNoGrab)
        w.pack(padx = 8, pady = 8)

        w = tkinter.Button(parent, text =
                    'Show toplevel window which\n' +
                    'will not get a busy cursor',
                command = self.showExcludedWindow)
        w.pack(padx = 8, pady = 8)

        # Create the dialog.
        self.dialog = Pmw.Dialog(parent,
            buttons = ('OK', 'Apply', 'Cancel', 'Help'),
            defaultbutton = 'OK',
            title = 'My dialog',
            command = self.execute)
        self.dialog.withdraw()

        # Add some contents to the dialog.
        w = tkinter.Label(self.dialog.interior(),
            text = 'Pmw Dialog\n(put your widgets here)',
            background = 'black',
            foreground = 'white',
            pady = 20)
        w.pack(expand = 1, fill = 'both', padx = 4, pady = 4)

        # Create the window excluded from showbusycursor.
        self.excluded = Pmw.MessageDialog(parent,
            title = 'I still work',
            message_text =
                'This window will not get\n' +
                'a busy cursor when modal dialogs\n' +
                'are activated.  In addition,\n' +
                'you can still interact with\n' +
                'this window when a "no grab"\n' +
                'modal dialog is displayed.')
        self.excluded.withdraw()
        Pmw.setbusycursorattributes(self.excluded.component('hull'),
            exclude = 1)

    def showAppModal(self):
        self.dialog.activate(geometry = 'centerscreenalways')

    def showGlobalModal(self):
        self.dialog.activate(globalMode = 1)

    def showDialogNoGrab(self):
        self.dialog.activate(globalMode = 'nograb')

    def showExcludedWindow(self):
        self.excluded.show()

    def execute(self, result):
        print('You clicked on ' + result)
        if result not in ('Apply', 'Help'):
            self.dialog.deactivate(result)

Pmw 2.1 - 31 Dec 2020 - Home
Manual page last reviewed: 18 May 2002