# /Usr/bin/Python # -*-<Coding = UTF-8> -*- """ This example shows how to add objects to a framework. The example in section 2.6 of wxpython """ Import WX Class Insertframe (wx. Frame ): Def _ Init __ (Self, parent, ID): WX. Frame. _ Init __ (Self, parent, ID, Title =" Frame with button " , Size = (300,100 )) # Create a panel control in Wx. Frame. Panel = Wx. Panel (Self) # Create a button control in Wx. Panel Button = wx. Button (panel, label = " Close " , Pos = (), size = (50, 50 )) # The click event of the BIND button. Note that the Wx. frame is bound to the oncloseme event, rather than other objects. Self. BIND (wx. evt_button, self. oncloseme, button) # Close event of the binding window Self. BIND (wx. evt_close, self. onclosewindow) Def Oncloseme (self, event ): # Where does the close method come from? after reading the API, wx. frame does not seem to have the close () method? Self. Close (true) Print Self. Close. _ Doc __ """ Close (self, bool force = false)-> bool this function simply generates a evt_close event whose handler usually tries to close the window. it doesn' t close the window itself, however. if force is false (the default) then the window's close handler will be allowed to veto the destruction of the window. """ Def Onclosewindow (self, event ): # The destroy () method is available only for WX. App. Why can wx. Frame be called? Self. Destroy () Print Self. Destroy. _ Doc __ """ Destroy (Self)-> bool destroys the window safely. frames and dialogs are not destroyed immediately when this function is called -- they are added to a list of windows to be deleted on idle time, when all the windows's events have been processed. this prevents problems with events being sent to non-existent windows. returns true if the window has either been successfully deleted, or it has been added to the list of Windows pending Real deletion. """ If _ Name __ = " _ Main __ " : App =Wx. pysimpleapp () Frame = Insertframe (parent = none, id =-1 ) Frame. Show () app. mainloop ()