Table Of Contents

Previous topic

MenuItem

Next topic

MessageParameters

This Page

phoenix_title MessageDialog

This class represents a dialog that shows a single or multi-line message, with a choice of OK, Yes, No and Cancel buttons.

styles Window Styles

This class supports the following styles:

  • OK: Puts an Ok button in the message box. May be combined with CANCEL .

  • CANCEL: Puts a Cancel button in the message box. Must be combined with either OK or YES_NO .

  • YES_NO: Puts Yes and No buttons in the message box. It is recommended to always use CANCEL with this style as otherwise the message box won’t have a close button under wxMSW and the user will be forced to answer it.

  • HELP: Puts a Help button to the message box. This button can have special appearance or be specially positioned if its label is not changed from the default one. Notice that using this button is not supported when showing a message box from non-main thread in OSX/Cocoa and it is not supported in OSX/Carbon at all.

    New in version 2.9.3..

  • NO_DEFAULT: Makes the “No” button default, can only be used with YES_NO .

  • CANCEL_DEFAULT: Makes the “Cancel” button default, can only be used with CANCEL

  • YES_DEFAULT: Makes the “Yes” button default, this is the default behaviour and this flag exists solely for symmetry with NO_DEFAULT .

  • OK_DEFAULT: Makes the “OK” button default, this is the default behaviour and this flag exists solely for symmetry with CANCEL_DEFAULT .

  • ICON_NONE: Displays no icon in the dialog if possible (an icon might still be displayed if the current platform mandates its use). This style may be used to prevent the dialog from using the default icon based on YES_NO presence as explained in ICON_QUESTION and ICON_INFORMATION documentation below.

  • ICON_EXCLAMATION: Displays an exclamation, or warning, icon in the dialog.

  • ICON_ERROR: Displays an error icon in the dialog.

  • ICON_HAND: Displays an error symbol, this is a MSW-inspired synonym for ICON_ERROR .

  • ICON_QUESTION: Displays a question mark symbol. This icon is automatically used with YES_NO so it’s usually unnecessary to specify it explicitly. This style is not supported for message dialogs under wxMSW when a task dialog is used to implement them (i.e. when running under Windows Vista or later) because Microsoft guidelines indicate that no icon should be used for routine confirmations. If it is specified, no icon will be displayed.

  • ICON_INFORMATION: Displays an information symbol. This icon is used by default if YES_NO is not given so it is usually unnecessary to specify it explicitly.

  • STAY_ON_TOP: Makes the message box stay on top of all other windows and not only just its parent (currently implemented only under MSW and GTK).

  • CENTRE: Centre the message box on its parent or on the screen if parent is not specified. Setting this style under MSW makes no differences as the dialog is always centered on the parent.

See also

MessageDialog Overview RichMessageDialog


class_hierarchy Inheritance Diagram

Inheritance diagram for class MessageDialog

Inheritance diagram of MessageDialog


method_summary Methods Summary

__init__ Constructor specifying the message box properties.
GetCancelLabel  
GetCaption  
GetEffectiveIcon  
GetExtendedMessage  
GetHelpLabel  
GetMessage  
GetMessageDialogStyle  
GetNoLabel  
GetOKLabel  
GetYesLabel  
HasCustomLabels  
SetExtendedMessage Sets the extended message for the dialog: this message is usually an extension of the short message specified in the constructor or set with SetMessage .
SetHelpLabel Sets the label for the Help button.
SetMessage Sets the message shown by the dialog.
SetOKCancelLabels Overrides the default labels of the OK and Cancel buttons.
SetOKLabel Overrides the default label of the OK button.
SetYesNoCancelLabels Overrides the default labels of the Yes, No and Cancel buttons.
SetYesNoLabels Overrides the default labels of the Yes and No buttons.
ShowModal Shows the dialog, returning one of ID_OK, ID_CANCEL, ID_YES, ID_NO or ID_HELP.

api Class API



class MessageDialog(Dialog)

This class represents a dialog that shows a single or multi-line message, with a choice of OK, Yes, No and Cancel buttons.

Possible constructors:

MessageDialog(parent, message, caption=MessageBoxCaptionStr,
              style=OK|CENTRE, pos=DefaultPosition)

Methods



__init__(self, parent, message, caption=MessageBoxCaptionStr, style=OK|CENTRE, pos=DefaultPosition)

Constructor specifying the message box properties.

Use ShowModal to show the dialog.

style may be a bit list of the identifiers described above.

Notice that not all styles are compatible: only one of OK and YES_NO may be specified (and one of them must be specified) and at most one default button style can be used and it is only valid if the corresponding button is shown in the message box.

Parameters:
  • parent (Window) – Parent window.
  • message (string) – Message to show in the dialog.
  • caption (string) – The dialog title.
  • style (long) – Combination of style flags described above.
  • pos (Point) – Dialog position (ignored under MSW).


GetCancelLabel(self)
Return type:string


GetCaption(self)
Return type:string


GetEffectiveIcon(self)
Return type:long


GetExtendedMessage(self)
Return type:string


GetHelpLabel(self)
Return type:string


GetMessage(self)
Return type:string


GetMessageDialogStyle(self)
Return type:long


GetNoLabel(self)
Return type:string


GetOKLabel(self)
Return type:string


GetYesLabel(self)
Return type:string


HasCustomLabels(self)
Return type:bool


SetExtendedMessage(self, extendedMessage)

Sets the extended message for the dialog: this message is usually an extension of the short message specified in the constructor or set with SetMessage .

If it is set, the main message appears highlighted – if supported – and this message appears beneath it in normal font. On the platforms which don’t support extended messages, it is simply appended to the normal message with an empty line separating them.

Parameters:extendedMessage (string) –

New in version 2.9.0.



SetHelpLabel(self, help)

Sets the label for the Help button.

Please see the remarks in SetYesNoLabels documentation.

Notice that changing the label of the help button resets its special status (if any, this depends on the platform) and it will be treated just like another button in this case.

Parameters:help (string) –
Return type:bool

New in version 2.9.3.



SetMessage(self, message)

Sets the message shown by the dialog.

Parameters:message (string) –

New in version 2.9.0.



SetOKCancelLabels(self, ok, cancel)

Overrides the default labels of the OK and Cancel buttons.

Please see the remarks in SetYesNoLabels documentation.

Parameters:
  • ok (string) –
  • cancel (string) –
Return type:

bool

New in version 2.9.0.



SetOKLabel(self, ok)

Overrides the default label of the OK button.

Please see the remarks in SetYesNoLabels documentation.

Parameters:ok (string) –
Return type:bool

New in version 2.9.0.



SetYesNoCancelLabels(self, yes, no, cancel)

Overrides the default labels of the Yes, No and Cancel buttons.

Please see the remarks in SetYesNoLabels documentation.

Parameters:
  • yes (string) –
  • no (string) –
  • cancel (string) –
Return type:

bool

New in version 2.9.0.



SetYesNoLabels(self, yes, no)

Overrides the default labels of the Yes and No buttons.

The arguments of this function can be either strings or one of the standard identifiers, such as ID_APPLY or ID_OPEN . Notice that even if the label is specified as an identifier, the return value of the dialog ShowModal method still remains one of ID_OK , ID_CANCEL , ID_YES or ID_NO values, i.e. this identifier changes only the label appearance but not the return code generated by the button. It is possible to mix stock identifiers and string labels in the same function call, for example:

dlg = wx.MessageDialog(parent, message, caption)
dlg.SetYesNoLabels(wx.ID_SAVE, "&Don't save")

Also notice that this function is not currently available on all platforms (although as of wxWidgets 2.9.0 it is implemented in all major ports), so it may return False to indicate that the labels couldn’t be changed. If it returns True, the labels were set successfully.

Typically, if the function was used successfully, the main dialog message may need to be changed, e.g.:

dlg = wx.MessageDialog(parent, message, caption)
if dlg.SetYesNoLabels("&Quit", "&Don't quit"):
    dlg.SetMessage("What do you want to do?")
else: # buttons have standard "Yes"/"No" values, so rephrase the question
    dlg.SetMessage("Do you really want to quit?")
Parameters:
  • yes (string) –
  • no (string) –
Return type:

bool

New in version 2.9.0.



ShowModal(self)

Shows the dialog, returning one of ID_OK, ID_CANCEL, ID_YES, ID_NO or ID_HELP.

Notice that this method returns the identifier of the button which was clicked unlike MessageBox function.

Return type:int

Properties



CancelLabel

See GetCancelLabel



Caption

See GetCaption



EffectiveIcon

See GetEffectiveIcon



ExtendedMessage

See GetExtendedMessage and SetExtendedMessage



HelpLabel

See GetHelpLabel and SetHelpLabel



Message

See GetMessage and SetMessage



MessageDialogStyle

See GetMessageDialogStyle



NoLabel

See GetNoLabel



OKLabel

See GetOKLabel and SetOKLabel



YesLabel

See GetYesLabel