This article illustrates the use of Python's wxpython and share it for everyone's reference. The specific methods are as follows:
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__": Main ()
Summarize the 4 steps for using Wxpython:
1. Import Wxpython Package
2. Subclass of Application Classes
3. Define an initialization method for an application
4. Create an instance of the application class (the subclass created in step 2nd)
5. Enter the main event loop for this instance of the application class created in step 4th
Note: Wxpython.jpg is this picture of Forrest Gump classmate, to and program in the same directory.
I hope this article will help you with your Python programming.