Search code examples
pythonwxpython

(MainWindow) Object has no attribute (go) [WxPython]


I'm working on making a bind event on a button refer to a function, however i get the error explained in the title.

I already have another bind event working and coded, and as far as i can tell there is zero difference between the two syntactically.

def OnBtnSuperTesting(self, event):
    class MainWindow(wx.Frame):
        def updateList(self, e):
            #########Defining some listbox possibilites
            T89 = [large array was here]
            T87AZ = [large array was here]
            T89ZA = T89AZ[::-1]
            T87ZA = T87AZ[::-1]
            #############    

            if  self.radioAtoZ.GetValue() == True:
                if self.radioT89.GetValue() == True:
                    choices = T89AZ
                else:
                    choices = T87AZ        
            elif self.radioZtoA.GetValue() == True:
                if  self.radioT89.GetValue() == True:
                    choices = T89ZA
                else:
                    choices = T87ZA
            else:
                if  self.radioT89.GetValue() == True:
                    choices = T89
                else:
                    choices = T87
            self.listbox.Set(choices)


        def Generate(self, e):
           #probably need a try except here
           selection = self.listbox.GetString(self.listbox.GetSelection())
           if self.radioT89 == True:    
               if selection == 'String name here':
                   self.pathname = 'pathname here (its coded)'

               #Assume the indentation here is right, StackOverflow isn't fommating this nicely
            self.lstCommands.AppendRows(1, 1)
       item = self.lstCommands.GetNumberRows()-1
       self.lstCommands.SetCellValue(item, 0, "Add Module")
       self.lstCommands.SetCellValue(item, 1, self.pathname)
           self.modifiedFlg = True

        def __init__(self, parent, title):

            self.dirname=''

            wx.Frame.__init__(self, parent, title=title, size=(320,440))
            self.SetBackgroundColour(wx.WHITE)
            self.CenterOnScreen()
            self.CreateStatusBar()
            self.radioT89 = wx.RadioButton(self, -1, 'T89 only', pos = (2,0), style = wx.RB_GROUP)
            self.radioT87 = wx.RadioButton(self, -1, 'T87 only', pos = (154, 0))
            self.radioKeySort = wx.RadioButton(self, -1, 'Sort by Key', pos = (2,40), style = wx.RB_GROUP)
            self.radioAtoZ = wx.RadioButton(self, -1, 'Sort Name A-Z', pos = (2,60))
            self.radioZtoA = wx.RadioButton(self, -1, 'Sort Name Z-A', pos = (2,80))
            self.checkCode = wx.CheckBox(self, -1, 'Generate Code', pos = (154,40))
            self.checkBuild = wx.CheckBox(self, -1, 'Generate Build Report', pos = (154, 60))
            self.ln = wx.StaticLine(self, -1, pos = (0,15), size = (300,3), style = wx.LI_HORIZONTAL)
            self.ln2 = wx.StaticLine(self, -1, pos = (150,15), size = (3,100), style = wx.LI_VERTICAL)

            self.radioT87.Bind(wx.EVT_RADIOBUTTON, self.updateList)
            self.radioT89.Bind(wx.EVT_RADIOBUTTON, self.updateList)
            self.radioKeySort.Bind(wx.EVT_RADIOBUTTON, self.updateList)
            self.radioAtoZ.Bind(wx.EVT_RADIOBUTTON, self.updateList)
            self.radioZtoA.Bind(wx.EVT_RADIOBUTTON, self.updateList)
            self.go.Bind(wx.EVT_BUTTON, self.Generate)



            self.go = wx.Button(self,-1, label = 'Go!', pos = (110, 325))



            # Setting up the menu.
            filemenu= wx.Menu()
            menuAbout= filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
            menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

            # Creating the menubar.
            menuBar = wx.MenuBar()
            menuBar.Append(filemenu,"&File") 
            self.SetMenuBar(menuBar) 

            # Events.
            self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
            self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)

            self.SetAutoLayout(1)

            self.Show()


                   def OnExit(self,e):
            self.Close(True)  # Close the frame.


    app = wx.App(False)
    frame = MainWindow(None, "Supervisory Testing")
    app.MainLoop()

So, you can see that the def updateList is indented the same as def Generate. It also has the same parameters and the same bind event syntax, with the exception that one is a radio button and the other is a button. What am i doing wrong?


Solution

  • You are binding to self.go in the line before you have asigned wx.Button to self.go, move the bind to after the button is created.