最近要做一个桌面应用程序,拿着python的那本指导书《wxPython in Action》操作,结果第一个例子就爆出错误:
Traceback (most recent call last):
NameError: name ‘App’ is not defined
跟别的代码比较了一下,发现是没有main()函数,在app定义前添加一行:
if __name__==’__main__’:
附上完整代码:
- #/bin/env python
- import wx
- class App(wx.App):
- def OnInit(self):
- frame = wx.Frame(parent=None, title=’Bare’)
- frame.Show()
- return True
- if __name__==’__main__‘:
- app = App()
- app.MainLoop()