Sending a message without using Western Union

The most basic mechanism for communicating with the user is wx.MessageDialog, which is a simple alert box. The wx.MessageDialog can be used as both a simple OK box, or as a yes/no dialog. The following snippet shows the yes/no behavior:

dlg = wx.MessageDialog(None, 'Is this the coolest thing ever!',

'MessageDialog', wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() dlg.Destroy()

The resulting dialog looks like figure 2.10, and the signature for the constructor is:

wx.MessageDialog(parent, message, caption="Message box", style=wx.OK | wx.CANCEL, pos=wx.DefaultPosition)

where parent is a parent window, or None if the dialog should be top-level. The message is the string which appears in the dialog, and the caption is the string that appears in the dialog's title bar. The style parameter is


Figure 2.10 A message dialog, configured for a yes/no response a bitmask which covers the buttons and icons displayed in the dialog, The pos parameter takes either a wx.Point or Python tuple, and allows you to specify the position of the dialog on the display, if you so desire.

The ShowModal() method displays the dialog as a modal frame, meaning that no other window in the application will respond to user events until the dialog is closed. This method is common to all dialogs. The return value of ShowModal() is an integer, signifying the result of the dialog. In this case, the result corresponds to the button pressed by the user. For a wx.MessageDialog, it will be one of the following constants: wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, or wx.ID_OK.

The style bits can be combined to manage the buttons displayed, with the legal values being wx.OK, wx,cancel, or wx.YES_NO. Style bits can also be used to set the icon displayed on the window, which is one of wx.icon_error, wx.ICON_EXCLAMATION, wx.ICON_INFORMATION, and wx.ICON_QUESTION.

Was this article helpful?

0 0

Post a comment