WxPython Modal Dialog mode Dialog box

Source: Internet
Author: User

WxPython in Action chap 9 notes

1. Modal Dialog (mode Dialog box)

A modal dialog blocks other widgets from processing user events until it is closed;

In other words, it places the user in dialog mode for the duration of its existence.

The Mode dialog box blocks other widgets from receiving user events until the mode dialog box is closed.

Strictly speaking, there is no difference in the appearance of the dialog and frame, but the way to handle events is different.

Generally, dialog is slightly simpler in appearance, so wx. Panel is rarely used.

Wx. Dialog has the property of wx. Panel. widgets is generally directly added to wx. Dialog.

2. Display and close the Dialog

The usage of Modal Dialog is slightly different from that of a normal Frame.

The simplest example code is as follows:

import wxclass SubclassDialog(wx.Dialog):    def __init__(self):        wx.Dialog.__init__(self, None, -1, 'Dialog Subclass', size=(300, 100))        okButton = wx.Button(self, wx.ID_OK, "OK", pos=(15, 15))        okButton.SetDefault()        cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel", pos=(115, 15))if __name__ == '__main__':    app = wx.PySimpleApp()    dialog = SubclassDialog()    result = dialog.ShowModal()    if result == wx.ID_OK:        print "OK"    else:        print "Cancel"    dialog.Destroy()

2.1 display Dialog

Display that the Dialog uses ShowModal (). The program waits until the ShowModal () Execution ends and obtains the returned value.

In this case, Dialog is the only component of the wxPython application that accepts user events. Other applications are not affected.

2.2 end Dialog Mode

Call the EndModal (retCode) method to disable (close) Dialog Mode. The retCode is an int value and is returned by ShowModal.

At this point, the Dialog Mode is ended and the Dialog Mode is not destroyed. This Dialog can be displayed elsewhere.

EndModal () is usually called in the event handler ().

2.3 destroy Dialog

Call the Destroy () method

2.4 typical usage
dialog == result ==  
2.5 handler of the Custom event, which generally needs to call EndModal ()

For example, the handler implementation used to connect to the database is as follows:

 OnConnect(self, event====  %, wx.OK | wx.ICON_ERROR)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.