【发布时间】:2014-07-18 21:24:04
【问题描述】:
我正在尝试制作一个接受两个文本输入的弹出窗口,然后当用户单击“确定”时,它会记录数据。我的问题是当我尝试定义按下“确定”按钮时的功能时,记录数据。当我按下确定时,我得到了AttributeError: 'apples' object has no attribute 'TextCtrlInstance'。
class apples(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Add a stock',size=(300,300))
frames=wx.Panel(self)
frames.Bind(wx.EVT_MOTION, self.OnMove)
frames.Bind(wx.EVT_MOTION, self.count)
howmuch=wx.TextCtrl(frames,-1,'#of',pos=(200,173))
cancel=wx.Button(frames,label='Cancel',pos=(100,250),size=(60,40))
self.Bind(wx.EVT_BUTTON, self.ca, cancel)
wx.StaticText(frames,-1,'Enter in valid stock ticker:',pos=(10,50))
what=wx.TextCtrl(frames,-1,'AAPL',pos=(200,48))
okbutton = wx.Button(frames,label='OK',pos=(200,250),size=(60,40))
self.Bind(wx.EVT_BUTTON,self.oker,okbutton)
wx.StaticText(frames,-1,'Enter in nuber of shares:',pos=(10,175))
def ca(self,event):
self.Destroy()
def oker(self,event):
#I need the user info when they press ok
print 'Saved!'
self.TextCtrlInstance.GetValue()
self.Destroy()
def OnMove(self,event):
pass
def count(self,event):
pass
if __name__ =='__main__':
apps = wx.PySimpleApp()
windows = apples(parent=None,id=-1)
windows.Show()
apps.MainLoop()
我希望这足以给我一个解决方案!谢谢,我期待答案!
【问题讨论】:
-
我对 wx 不熟悉,但是我没有看到
TextCtrlInstance是在哪里定义的。 -
在 Python 中有一种用法,即 类名 具有大写首字母,而 实例名 以小写开头。像所有的编码约定一样,这也是有争议的。但是,我建议您暂时坚持使用这种用法,因为这可能有助于您区分代码中的 类 和 对象。
标签: python python-2.7 wxpython