我的代码很简单,但我不断收到以下错误.我研究了错误,它几乎说IDLE和我自己的GUI相互搞砸,但我真的不知道如何避免它.我的意思是,如果我只是在没有IDLE打开的情况下点击我的GUI的.py文件,我会得到同样的错误.
有任何想法吗?
Python 2.7
Windows XP
import wx
class applicationName(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Title', size=(300,200))
panel = wx.Panel(self)
box = wx.TextEntryDialog(None, "How old are you?", "Title", "default text")
if box.ShowModal() == wx.ID_OK:
answer = box.GetValue()
if __name__ =='__main__':
app = wx.PySimpleApp()
frame = applicationName(parent=None, id=-1)
frame.Show()
app.MainLoop()
错误:
PyNoAppError:必须首先创建wx.App对象!
解决方法:
您的__init__函数没有正确缩进.它应该是
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Title', size=(300,200))
panel = wx.Panel(self)
box = wx.TextEntryDialog(None, "How old are you?", "Title", "default text")
if box.ShowModal() == wx.ID_OK:
answer = box.GetValue()
标签:python,user-interface,wxpython