在我对以下程序进行一些更改之前,一切都很顺利:
修改前的程序:
#! /usr/bin/env python
""" A bare-minimum wxPython program """
import wx
class MyApp(wx.App):
def OnInit(self):
return True
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame(None, "Sample")
frame.Show(True)
app.MainLoop()
但是在我frame
输入 的定义后OnInit
,程序运行时没有语法错误,但没有显示任何内容。:(
修改后的程序:
#! /usr/bin/env python
""" A bare-minimum wxPython program """
import wx
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, "Sample") ## add two lines here
self.frame.Show(True)
return True
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
if __name__ == '__main__':
app = wx.App()
app.MainLoop()
我尝试使用调试器并单步执行程序。似乎self.frame
没有定义(甚至从头到尾都没有出现)。
我的程序出了什么问题?我对 Python 和 wxPython 很陌生,请帮忙。谢谢。
编辑:
app = MyApp()
标准输出/标准错误:
NameError: global name 'Show' is not defined