简体   繁体   English

如何在另一个函数中使用从wxPython按钮返回的值?

[英]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.

相关问题 如何在python的另一个应用程序中使用函数返回的值? - How can I use a value returned by a function in another application in python? 如何从一个函数中获取一个值并在另一个函数中使用它? - How do I take a value from one function and use it in another? 如何使用 wxpython 中的按钮从 slider 获取信息? - How do i get information from a slider using button in wxpython? 如何存储函数的第二个返回值? - How do I store the second returned value from a function? 如何通过按下按钮从 tkinter 输入字段返回变量以在另一个 function 中使用? - How do I return a variable from a tkinter Entry field to use in another function by pressing a button? python 将另一个 function 的返回值设置为在 header 中使用的变量 - python set returned value from another function as a variable to use in header Flask - 如何在 Python ZC1C425268E18385D1AB44A 中使用 HTML 按钮的值? - Flask - How do I use the value of an HTML button in a Python function? 如何启动和使用wxPython? - How do I start and use wxPython? 将返回的函数值存储在列表WXpython中 - store returned function value in a list WXpython 如何在另一个函数中使用一个函数的两个返回值? 主要() - How to use two returned values from a function in another function? MAIN()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM