WxPython:type object';测试';没有属性';openReportButton';

WxPython:type object';测试';没有属性';openReportButton';,wxpython,Wxpython,我试图在点击另一个按钮时启用一个按钮,但它总是给我这个错误(见标题) 我错过了什么 谢谢,您需要将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_BO

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

我错过了什么


谢谢,

您需要将
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()
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()