【问题标题】:How do I use a value returned from a wxPython button in another function?如何在另一个函数中使用从 wxPython 按钮返回的值?
【发布时间】:2014-03-11 15:01:48
【问题描述】:

我正在自学 Python/wxPython,所以提前为我的问题的新手性质和任何不正确的术语道歉。

我在这里搜索了网络和其他建议的答案,但似乎找不到我要找的东西。

我有以下按钮,它返回一个打开的文件 (.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

我想在另一个函数中使用 input1。谁能告诉我怎么做?

for line in input1:

很明显会抛出input1未定义的错误。

提前致谢。

【问题讨论】:

    标签: python function button wxpython return


    【解决方案1】:

    调用函数会返回一些数据。你需要存储这个,例如:

    self.some_var = self.onHydroInputButton(event)

    现在函数的输出存储在self.some_var中。

    【讨论】:

    • 非常感谢。专家们必须回答这些基本问题一定很痛苦,不胜感激。
    猜你喜欢
    • 2021-05-31
    • 2022-11-23
    • 2021-12-11
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多