The first lesson of all programming languages is basically a simple small program "Hello World", which is the same as "Hello world". The difference is "Hello World!
Program meta code:
The following Hello World Program uses wxpython to show the wxpython logo. For more information, see the following code:
#! /Usr/bin/ENV python <br/> "" Hello, wxpython! Program. "<br/> Import wx <br/> class frame (wx. frame): <br/> "" frame class that displays an image. "</P> <p> def _ init _ (self, image, parent = none, id =-1, Pos = wx. defaultposition, Title = "Hello, wxpython! "): <Br/>" "Create a frame instance and display image. "<br/> temp = image. converttobitmap () <br/> size = temp. getwidth (), temp. getheight () <br/> wx. frame. _ init _ (self, parent, ID, title, POs, size) <br/> self.bmp = wx. staticbitmap (parent = self, bitmap = temp) </P> <p> class app (wx. APP): <br/> "" application class. "</P> <p> def oninit (Self): <br/> image = wx.image('wxpython.jpg ', wx. bitmap_type_jpeg) <br/> self. frame = frame (image) <br/> self. frame. show () <br/> self. settopwindow (self. frame) <br/> return true </P> <p> def main (): <br/> APP = app () <br/> app. mainloop () </P> <p> If _ name _ = '_ main _': <br/> main () <br/>
Line-by-line description (the same content as the Wx entry will not be explained ):
1. An Image Display Control is added to the frame.
Def _ init _ (self, image, parent = none, id =-1, Pos = wx. defaultposition, Title = "Hello, wxpython! "):
"Create a frame instance and display image ."""
Temp = image. converttobitmap ()
Size = temp. getwidth (), temp. getheight ()
Wx. Frame. _ init _ (self, parent, ID, title, POs, size)
Self.bmp = wx. staticbitmap (parent = self, bitmap = temp)
Input an image object,
Convert this object to bitmap,
Obtain the initial size of the image and set it to the initial size of the frame.
Use the staticbitmap space to display this image
2. oninit method of app
Def oninit (Self ):
Image = wx.image('wxpython.jpg ', wx. bitmap_type_jpeg)
Self. Frame = frame (image)
Self. Frame. Show ()
Self. settopwindow (self. Frame)
Return true
Obtain an image object and pass it to the frame
3. Define a main method. See the following code:
Def main ():
APP = app ()
App. mainloop ()
4. Call the main method using the conventional method
If _ name _ = '_ main __':
Main ()
See for the running effect: