Use Python to develop a Windows GUI program entry instance

Source: Internet
Author: User
This article mainly introduces how to use Python to develop a Windows GUI program entry instance. This article focuses on the software necessary for the development environment, and the code implementation is relatively simple, for more information, see wxPython. Write down some notes for your reference. On windows XP, configure the following environment:

1. install python first. after installation, add the directory of python/bin to path.
2. install wxPython. Note that the wxPython version must be consistent with the previous python version.
3. install py2exe. this is a very good python program release tool on the windows platform. it can compile the python program into an exe and run it out of the python environment. After the above installation, we can test it.

WxPython demo code:

The code is as follows:


# WxDemo. py

Import wx

Class App (wx. App ):
Def OnInit (self ):
Frame = wx. Frame (parent = None, title = 'bare ')
Frame. Show ()
Return True

App = App ()
App. MainLoop ()

Compile the compilation code for py2exe:

The code is as follows:


# Setup. py
From distutils. core import setup
Import py2exe

Setup (windows = ["wxDemo. py"])

Note that setup (windows = ["wxDemo. py "]) to correctly reference your Python program, the python program file to be compiled in [] uses the windows attribute because it contains a window.

Compile as follows:

Run python setup. py py2exe on the command line and put the handler in the same directory. Otherwise, the program cannot be executed. Now, double-click wxdemo.exe and you will see a window :)

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.