Python in Action: Second, smallest GUI program: small, perfectly formed

Source: Internet
Author: User

Python in action The second example, is very simple, but is the most basic GUI program framework, there is the most basic implementation GUI process

1 ImportWX2 classMyApp (WX. APP):3     defOnInit (self):4Frame=wx. Frame (parent=none,title='Bare')5 frame. Show ()6         returnTrue7app=MyApp ()8App. Mainloop ()

Results:

It is necessary to mention the first line: Import WX This statement is imported WX module, this module is complex (from the Python in Action), the book is about this module and the old module import method, but this is not the old module, so do not have to tube old package How to import, anyway, now not used. You can also change the import WX to: from WX import *, so that the program can omit the prefix wx., called directly in the app () mode.

Next, define a own App (), MyApp does not rewrite the __iinit__ () method, but is called by the parent class, if you want to override the __init__ () method, be sure to remember to display the __init__ method that calls the parent class: wx.app.__init__ (self Otherwise, the OnInit () method does not take effect. This can be introduced: the OnInit () method is called by the __init__ method of the parent class.

Finally enters the message loop, responding to various events.

Next post: Slightly expanded

Python in Action: Second, smallest GUI program: small, perfectly formed

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.