Wxpython "Hello world !"

Source: Internet
Author: User

The first lesson of all programming languages is basically a simple small program "Hello World", which is the same as "Hello world". The difference is "Hello World!

 

Program meta code:

The following Hello World Program uses wxpython to show the wxpython logo. For more information, see the following code:

 

#! /Usr/bin/ENV python <br/> "" Hello, wxpython! Program. "<br/> Import wx <br/> class frame (wx. frame): <br/> "" frame class that displays an image. "</P> <p> def _ init _ (self, image, parent = none, id =-1, Pos = wx. defaultposition, Title = "Hello, wxpython! "): <Br/>" "Create a frame instance and display image. "<br/> temp = image. converttobitmap () <br/> size = temp. getwidth (), temp. getheight () <br/> wx. frame. _ init _ (self, parent, ID, title, POs, size) <br/> self.bmp = wx. staticbitmap (parent = self, bitmap = temp) </P> <p> class app (wx. APP): <br/> "" application class. "</P> <p> def oninit (Self): <br/> image = wx.image('wxpython.jpg ', wx. bitmap_type_jpeg) <br/> self. frame = frame (image) <br/> self. frame. show () <br/> self. settopwindow (self. frame) <br/> return true </P> <p> def main (): <br/> APP = app () <br/> app. mainloop () </P> <p> If _ name _ = '_ main _': <br/> main () <br/> 

 

Line-by-line description (the same content as the Wx entry will not be explained ):

1. An Image Display Control is added to the frame.

 

Def _ init _ (self, image, parent = none, id =-1, Pos = wx. defaultposition, Title = "Hello, wxpython! "):

"Create a frame instance and display 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)

 

 

Input an image object,

Convert this object to bitmap,

Obtain the initial size of the image and set it to the initial size of the frame.

Use the staticbitmap space to display this image

 

2. oninit method of app

 

Def oninit (Self ):

Image = wx.image('wxpython.jpg ', wx. bitmap_type_jpeg)

Self. Frame = frame (image)

Self. Frame. Show ()

Self. settopwindow (self. Frame)

Return true

 

 

Obtain an image object and pass it to the frame

 

3. Define a main method. See the following code:

 

Def main ():

APP = app ()

App. mainloop ()

 

 

4. Call the main method using the conventional method

 

If _ name _ = '_ main __':

Main ()

 

 

See for the running effect:

 

 

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.