# ! /Usr/bin/Python # -*-<Coding = UTF-8> -*- Import WX Class Myframe (wx. Frame ): Def _ Init __ (Self ): """ Defines the _ init _ method, which is equivalent to constructors of other object-oriented languages. It is automatically called when a class object is created. """ # Why do I need to call the initialization function of the parent class? Of course, the initialization of the parent class is also automatically called. Wx. Frame. _ Init __ (Self, none,-1, " Myframe " , Size = (300,300 )) # Create a panel control Panel = wx. Panel (self,-1 ) # Event binding type: WX. Motion, mainly used to detect mouse movement. Panel. BIND (wx. evt_motion, self. onmove) # Create a static file to display information on the panel. Wx. statictext (panel,-1, " POs: " , Pos = (10, 12 )) """ Create a text input box and assign this object to self. posctrl. I have never understood why I should assign a value to self. posctrl. it seems that the variable defined in the _ init _ method can be referenced in the whole class method. In the onmove () method below, I don't know whether to understand it, right. """ Self. posctrl = Wx. textctrl (panel,-1, "" , Pos = (40, 10 )) Def Onmove (self, event ): """ Self. onmove is called by the BIND function. However, this place has always been very abrupt. It is not clear how the event is passed and operated. """ Pos = Event. getposition () # Display the current cursor position in the text box Self. posctrl. setvalue ( " % S, % s " % (Pos. X, POS. y )) If _ Name __ = ' _ Main __ ' : App = Wx. pysimpleapp () Frame = Myframe () frame. Show (true) app. mainloop ()