From wxpython.wx import * id_about = 101 id_exit = 102 class myframe (wxframe): Def __init, id, title): wxframe .__ init__ (self, parent, id, title, wxdefault, wxSIze (200, 150) ) self.CreateStatusBar () self.SetStatusText ( "This is the statusbar") menu = wxMenu () menu.Append (ID_ABOUT, "& About", "More information about this program") menu.AppendSeparator () menu.Append (ID_EXIT , "E & XIT", "Terminate the Program" MenuBar = wxmenubar () MenuBar.Append (Menu, "& File"); self.setmenubar (menubar) ######################################################################################################################################################################################################################################### ############ EVT_MENU (Self, id_about, self.onabout) evt_menu (self, id_exit, self.timetoquit) Def onain (self): DLG = WxMessageDialog (Self, "this sample program Shows Off / N "" Frames, Menus, Statusbars, And this / N "" Message Dialog. "," About Me ", wxok | wxicon_inf ORMATION) DLG.ShowModal () DLG.DESTROY () DEF TIMETOQUIT (Self, Event): Self.close (True) ############################################################################################################################################################################################################################################## ###### Class myApp (wxapp): def OnInit (self): frame = myframe (null, -1, "hello from wxpython) frame.show (true) self.SettopWindow (frame) Return True App = myApp (0) app.mainloop ()
As above, the only difference from the previous version is that it is addressed to the process of About and Exit menu events.
The event is a special property, a method pointer. He follows the "Hollywood Classes", "Don't call us, we will call you."
WxMessageDialog is a common dialog. It can be used as a About window, a prompt window, and so on.
EVT_ * Tell this is an event help function,
EVT_MENU tells the program that this function is processed by the menu,
EVT_MENU (Self, id_about, self.onabout "tells the program that the response is the menu item named ID_about presses the event.