Python in Action: A small example of getting started

Source: Internet
Author: User

Python in action The book is a bit of a hit, and it starts with an example:

1 ImportWX2 classMyFrame (WX. Frame):3     def __init__(self):4Wx. Frame.__init__(Self,none,-1,'My Frame', Size= (300,300))5Panel=wx. Panel (self,-1)6 panel. Bind (WX. Evt_motion,self. OnMove)7Wx. Statictext (Panel,-1,'Pos:', pos= (10,12))8Self.posctrl=wx. Textctrl (Panel,-1,"', pos= (40,10))9     defOnMove (self,event):Tenpos=event. GetPosition () OneSelf.posCtrl.SetValue ("%s,%s"%(POS.X,POS.Y)) A if __name__=='__main__': -app=WX. APP () -Frame=MyFrame () the frame. Show () -App. Mainloop ()

Operation Result:

Running this program will cause an error on my machine: DLL load failed:%1 is not a valid WIN32 application.

Because my computer Python is loaded with 32 bits, the next is Wxpython64 bit

Just re-overwrite the installation with the next 32-bit wxpython.

In my understanding:

First, create a frame class that overrides the parent class's initialization function __init__, adds a panel Panel:panel=panel (self,-1), and self means that the parent window is the frame,-1 is the ID

This program is powerful in that the mouse movement of the event binding is done directly with a statement:

Panel. Bind (WX. Evt_motion,self. OnMove)

If this is placed in Java, you should not first create a listener: Xxxlistener, and then in the listener, implement a method: OnXXX (Xxxevent), and finally register the listener.
It's really a lot more hassle than python.

Next: the smallest GUI program

Python in Action: A small example of getting started

Related Article

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.