[WxPython笔记2] after Hello world

[WxPython笔记2] after Hello world

#  2008 . May. 21

import  wx

class  MyFrame(wx.Frame):
    
    
def   __init__ (self, title, pos, size):
        wx.Frame.
__init__ (self, None,  - 1 , title, pos, size)
        menuFile 
=  wx.Menu() 
        menuFile.Append(
1 " &About "
        menuFile.AppendSeparator() 
        menuFile.Append(
2 " E&xit "
        menuBar 
=  wx.MenuBar() 
        menuBar.Append(menuFile, 
" &File "
        self.SetMenuBar(menuBar) 
        self.CreateStatusBar() 
        self.SetStatusText(
" Welcome to wxPython! "
        self.Bind(wx.EVT_MENU, self.OnAbout, id
= 1
        self.Bind(wx.EVT_MENU, self.OnQuit, id
= 2
        
    
def  OnQuit(self, event): 
            self.Close() 
             
    
def  OnAbout(self, event): 
            wx.MessageBox(
" This is a wxPython Hello world sample "
                    
" About Hello World " , wx.OK  |  wx.ICON_INFORMATION, self) 
                    

class  MyApp(wx.App):
    
    
def  OnInit(self):
        self.frame 
=  MyFrame( ' hello world ' , ( 50 60 ), ( 450 340 ))
        self.frame.Show()
        self.SetTopWindow(self.frame)
        
return  True
    

if   __name__   ==   ' __main__ '
    app 
=  MyApp(False) 
    app.MainLoop() 
    

Most of the wxPython toolkit is accessed through the wx package which you
access using the import wx statement. Every wxPython program must have
an application object—an instance of  a wx.App subclass that defines an
OnInit() method. Most wxPython programs will have one or more
frames—instances of subclasses of wx.Frame. A frame is the large, movable,
resizeable window-like container that appears on screen, often with a menu,
status bar, tool bars, and other widgets. Control of your program passes to
wxPython when you call your application’s MainLoop() method.

[WxPython笔记2] after Hello world_第1张图片

你可能感兴趣的:([WxPython笔记2] after Hello world)