主题:[讨论]python调试的问题
求教:WXPYTHON代码没有错误,第一次运行也正常,可以后接着再次运行的时候就会出现解释器错误,然后退出.是什么原因呀?
#!/usr/bin/env python
import wx
import sys
class Frame(wx.Frame):
def __init__(self, parent, id, title):
print "Frame __init__"
wx.Frame.__init__(self, parent, id, title)
class App(wx.App):
def __init__(self, redirect=True, filename=None):
print "App __init__"
wx.App.__init__(self, redirect, filename)
def OnInit(self):
print "OnInit"
self.frame = Frame(parent=None, id=-1, title='Startup')
self.frame.Show()
self.SetTopWindow(self.frame)
print >> sys.stderr, "A pretend error message"
print "app name: <", self.GetVendorName(), ">"
return True
def OnExit(self):
print "OnExit"
if __name__ == '__main__':
app = App(redirect=True)
print "before MainLoop"
fred = app.MainLoop()
print "after MainLoop", fred
运行环境active python
第二次在其中运行时出错信息Traceback (most recent call last):
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\wxPythonInAction-src\Chapter-02\startup.py", line 28, in OnExit
print "OnExit"
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\python\lib\site-packages\wx-2.6-msw-ansi\wx\_core.py", line 7351, in write
self.CreateOutputWindow(text)
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\python\lib\site-packages\wx-2.6-msw-ansi\wx\_core.py", line 7325, in CreateOutputWindow
style=wx.DEFAULT_FRAME_STYLE)
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\python\lib\site-packages\wx-2.6-msw-ansi\wx\_windows.py", line 484, in __init__
newobj = _windows_.new_Frame(*args, **kwargs)
TypeError: argument number 1: a 'wxWindow *' is expected, '_wxPyDeadObject(wxPython wrapper for DELETED Frame object! (The C++ object no longer exists.))' is received
after MainLoop None
#!/usr/bin/env python
import wx
import sys
class Frame(wx.Frame):
def __init__(self, parent, id, title):
print "Frame __init__"
wx.Frame.__init__(self, parent, id, title)
class App(wx.App):
def __init__(self, redirect=True, filename=None):
print "App __init__"
wx.App.__init__(self, redirect, filename)
def OnInit(self):
print "OnInit"
self.frame = Frame(parent=None, id=-1, title='Startup')
self.frame.Show()
self.SetTopWindow(self.frame)
print >> sys.stderr, "A pretend error message"
print "app name: <", self.GetVendorName(), ">"
return True
def OnExit(self):
print "OnExit"
if __name__ == '__main__':
app = App(redirect=True)
print "before MainLoop"
fred = app.MainLoop()
print "after MainLoop", fred
运行环境active python
第二次在其中运行时出错信息Traceback (most recent call last):
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\wxPythonInAction-src\Chapter-02\startup.py", line 28, in OnExit
print "OnExit"
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\python\lib\site-packages\wx-2.6-msw-ansi\wx\_core.py", line 7351, in write
self.CreateOutputWindow(text)
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\python\lib\site-packages\wx-2.6-msw-ansi\wx\_core.py", line 7325, in CreateOutputWindow
style=wx.DEFAULT_FRAME_STYLE)
File "C:\Program Files\Common Files\Adobe\Acrobat\CIDFont\Python24\python\lib\site-packages\wx-2.6-msw-ansi\wx\_windows.py", line 484, in __init__
newobj = _windows_.new_Frame(*args, **kwargs)
TypeError: argument number 1: a 'wxWindow *' is expected, '_wxPyDeadObject(wxPython wrapper for DELETED Frame object! (The C++ object no longer exists.))' is received
after MainLoop None