The example of this paper describes the use of Python wxpython, share for everyone to reference. Here's how:
First look at the effect, here to load a picture:
The code is as follows:
#!/usr/bin/env python "" "" Hello WxPython Program "" " import Wx class Frame (WX. FRAME): #wxPrame subclass "" " Frame class that display a image" "" def __init__ (self, image, Parent=none, id=-1,
pos=wx. Defaultposition, title= "Hello, WxPython"): #3 #create a Frame instance and display a 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) Pass class App (WX. APP): #5 wx. APP subclass "" " Application Class" " def OnInit (self): image = Wx. Image (' wxpython.jpg ', WX. Bitmap_type_jpeg) Self.frame = FRAME (image) self.frame.Show (True) Self . Settopwindow (self.frame) return True def main (): App = App () app . Mainloop () if __name__ = = "__main__":
Summarize the 4 steps for using Wxpython:
1. Import Wxpython Package
2. Subclasses of application classes
3. Defining an application's initialization method
4. Create an instance of the application class (the subclass created in step 2nd)
5. Enter the main event loop of the application class instance created in step 4th
Note: Wxpython.jpg is this picture of Forrest Gump classmate, and the program in the same directory.
Hopefully this article will help you with Python programming.