之前每次运行程序时,第一次都可以正常生成GUI,但是第二次程序就会报错:PyNoAppError: The wx.App object must be created first!
后来研究发现,在程序的最开头加上del app可以有效解决此问题
E.g.:
#派生Frame的子类,修改了原来Frame子类的__init__()方法
del app #防止出错PyNoAppError: The wx.App object must be created first!
import wx
class Frame1(wx.Frame):
def __init__(self, superior):
wx.Frame.__init__(self, parent = superior, title = 'Example',
pos = (100,200), size = (350,200))
panel = wx.Panel(self)
text1 = wx.TextCtrl(panel, value = 'Hello, World!', size = (350,200))
if __name__ == '__main__':
app = wx.App()
frame = Frame1(None)
frame.Show(True)
app.MainLoop()