gpt4 book ai didi

python - 当用户在python中单击 'ok'时,如何保存用户文本框输入?

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:09 27 4
gpt4 key购买 nike

我正在尝试制作一个弹出窗口,该窗口需要两个文本输入,然后当用户单击“确定”时,它会记录数据。我的问题是,当我尝试定义按下“确定”按钮时的功能时,记录数据。当我按“确定”时,我收到 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()

我希望这足以给我一个解决方案!谢谢,我期待答案!

最佳答案

一个有根据的猜测,因为我没有运行你的代码:

def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Add a stock',size=(300,300))
self.frames=wx.Panel(self)
self.frames.Bind(wx.EVT_MOTION, self.OnMove)
self.frames.Bind(wx.EVT_MOTION, self.count)
self.howmuch=wx.TextCtrl(frames,-1,'#of',pos=(200,173))
self.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))
self.what=wx.TextCtrl(frames,-1,'AAPL',pos=(200,48))
self.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 oker(self,event):
qty = self.howmuch.GetValue()
what = self.what.GetValue()
print "Saved", qty, "of", what

如果您需要从同一对象的其他方法访问它们,则需要将各种小部件存储为实例变量。在 Python 中,这写作 self.varname = ....。通常来自 __init__ 特殊方法。您可能错过了其中的一些(也许不是我添加的所有内容 - YMMV)

然后,GetValue是 TextCtrl 类的一个方法。为了使用它,必须在该类的实例上调用它。

根据您的代码,TextCtrl 的唯一两个(可见)实例是“self.howmuch”和“self.what”。

关于python - 当用户在python中单击 'ok'时,如何保存用户文本框输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24834010/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com