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