WxPython application example of python

Source: Internet
Author: User
This article mainly introduces the wxPython application example of python. taking loading images as an example, it describes the usage of wxPython, which is of great practical value, for more information about how to use python wxPython, see the examples in this article. The specific method is as follows:

Let's take a look at the effect. here we load an image:

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() 

To sum up the four steps for using wxPython:

1. import the wxPython package
2. subclass application class
3. define the initialization method of an application
4. create an instance of the application class (subclass created in step 1)
5. go to the main event loop of the application-class instance created in step 1.

Note: wxPython.jpg is an image of a. Gump, which must be in the same directory as the program.

I hope 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.