This article describes a Windows GUI program that is based on the Wxpython implementation. Share to everyone for your reference. Specific as follows:
# using a WX. Frame, WX. MenuBar, WX. Menu, WX. Panel, WX. Statictext, WX. Button, # and a wx. Boxsizer to show a rudimentary wxPython Windows GUI application# WxPython Package from:http://prdownloads.sourceforge.net /wxpython/# I downloaded:wxpython2.5-win32-ansi-2.5.3.1-py23.exe# If you had not already do so install the Python comp Iler first# I used Python-2.3.4.exe (the Windows installer package for Python23) # from http://www.python.org/2.3.4/# test Ed with Python23 vegaseat 24jan2005import wxclass Frame1 (WX. Frame): # Create a simple Windows frame (sometimes called form) # pos= (ulcx,ulcy) size= (width,height) in pixels def __i Nit__ (self, Parent, title): WX. Frame.__init__ (self, parent,-1, title, pos= (), size= (+)) # Create a menubar at the top of the user Fram E MenuBar = wx. MenuBar () # Create a menu ... menu = wx. Menu () # ... add an item to the menu # \talt-x creates a accelerator for Exit (Alt + X keys) # The third Paramet ER is an optional Hint that shows on # The statusbar when the cursor is moves across this menu item menu. Append (Wx.id_exit, "E&xit\talt-x", "EXIT The Program") # Bind the menu event to an event handler, share QUITBTN Eve NT self. Bind (WX. Evt_menu, self. Onquitbutton, Id=wx.id_exit) # Put the menu on the MenuBar menubar.append (menu, ' &file ') self. Setmenubar (MenuBar) # Create a status bar at the bottom of the frame self. Createstatusbar () # Now create a panel (between menubar and statusbar) ... panel = wx. Panel (self) # ... put some controls on the panel text = wx. Statictext (Panel,-1, "Hello world!") Text. SetFont (WX. Font (WX. SCRIPT, WX. NORMAL, WX. BOLD)) text. SetSize (text. Getbestsize ()) quitbtn = WX. button (Panel,-1, "Quit") messbtn = wx. button (Panel,-1, "Message") # Bind the button events to event handlers self. Bind (WX. Evt_button, self. Onquitbutton, quitbtn) self. Bind (WX. Evt_button, self. Onmessbutton, MESSBTN) # Use a Sizer to layout The controls, stacked vertically # with a ten pixel border around each Sizer = wx. Boxsizer (WX. VERTICAL) Sizer. ADD (text, 0, WX. All, ten) Sizer. ADD (quitbtn, 0, WX. All, ten) Sizer. ADD (messbtn, 0, WX. All, ten) panel. Setsizer (Sizer) panel. Layout () def onquitbutton (self, evt): # event handler for the Quit button click or Exit menu item print ' See you LA ter alligator! (Goes to stdout window) "WX. Sleep (1) # 1 second to look at message self. Close () def onmessbutton (self, evt): # event handler-the Message button click Self. Setstatustext (' 101 Different Ways to Spell ' Spam ') class Wxpyapp (WX. APP): def OnInit (self): # Set the title Too frame = Frame1 (None, "WxPython GUI 2") self. Settopwindow (frame) frame. Show (True) return true# get it going ... app = Wxpyapp (redirect=true) app. Mainloop ()
Hopefully this article will help you with Python programming.