补充说明上次的wx.App类,wx.App是应用程序的基类,它会在方法调用wx.Frame类,然后循环调用自己的方法,来运行一个完整的应用程序。如何解释这个事情呢,程序员的方法—你站在这里别动,我打几行代码给你看看,就几行。
wx.App类的运行过程
#coding:utf-8
import wx
import time
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,'Hello World',size=(300,300))
panel = wx.Panel(self)
txt = wx.StaticText(panel,-1,'Hello world')
self.Centre()
class MyApp(wx.App):
def OnInit(self):
print('App Oninit')
self.frame = MyFrame()
self.frame.Show()
return True
def OnExit(self):
print('App OnExit')
time.sleep(3)
return True
print('App start')
app = MyApp()
print('before Mainloop')
app.MainLoop()
print('after Mainloop')
代码如上,比起上次的代码,这次多了MyApp类(继承了wx.App),用来解释整个过程。从wx.App类的运行开始说起:
print('App start')
app = MyApp()
print('before Mainloop')
跟其他类创建的对象时类似,会先调用其的构造方法,而wx.App程序在创建对象时,则是会调用On