[英]How do I use a value returned from a wxPython button in another function?
I'm teaching myself Python/wxPython so apologies in advance for the newbie nature of my question and any incorrect terminology. 我正在自学Python / wxPython,因此请为我的问题的新手性质和任何不正确的术语而道歉。
I've trawled the web and other suggested answers on here but I can't seem to find what I'm looking for. 我在这里拖网和其他建议的答案,但似乎找不到我想要的东西。
I've got the following button that returns an open file (.txt) object: 我有以下按钮可返回打开文件(.txt)对象:
def onHydroInputButton(self, event):
dlg = wx.FileDialog(self, "Select file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
input1 = open(dlg.GetPath())
dlg.Destroy()
return input1
I'd like to use input1 in another function. 我想在另一个函数中使用input1。 Could anybody show me how please? 有人可以告诉我如何吗?
for line in input1:
Obviously throws up an error that input1 is not defined. 显然引发未定义input1的错误。
Thanks in advance. 提前致谢。
Calling the function returns some data. 调用该函数将返回一些数据。 You need to store this, eg: 您需要存储它,例如:
self.some_var = self.onHydroInputButton(event)
Now the output of the function is stored in self.some_var
. 现在,函数的输出存储在self.some_var
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.