Python's Wxpython application example

Source: Internet
Author: User
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.

  • 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.