Python's Wxpython application example _python

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.