WxPython: 类型 object 'Test' 没有属性 'openReportButton'

WxPython: type object 'Test' has no attribute 'openReportButton'

我试图在点击另一个按钮时启用一个按钮,但它一直给我这个错误(见标题)

class Test(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id, "Frame aka Window", style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX, size=(400, 635))

        loadData = wx.Button(panel, label="Load Data", size = (100,40))
        loadData.SetFont(font)
        self.Bind(wx.EVT_BUTTON, self.loadData, loadData)

        openReportButton = wx.Button(panel, label = "Open Report", size = (100,40))
        openReportButton.SetFont(font)
        openReportButton.Disable()
        self.Bind(wx.EVT_BUTTON, self.openReport, openReportButton)

    def loadData(self, event):
        self.openReportButton.Enable()

我在这里错过了什么?

谢谢,

您需要使 openReportButton 成为实例属性(而不仅仅是局部变量)

class Test(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id, "Frame aka Window", style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX, size=(400, 635))

        loadData = wx.Button(panel, label="Load Data", size = (100,40))
        loadData.SetFont(font)
        self.Bind(wx.EVT_BUTTON, self.loadData, loadData)
        # added "self."
        self.openReportButton = wx.Button(panel, label = "Open Report", size = (100,40))
        self.openReportButton.SetFont(font)
        self.openReportButton.Disable()
        self.Bind(wx.EVT_BUTTON, self.openReport, openReportButton)

    def loadData(self, event):
        self.openReportButton.Enable()