(Main Window) object does not have attribute (go)

#Assume the indentation in the code is right (but you can still ask to check with me), it isn’t fommating this nicely

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)'
                   
               
            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?

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

It’s just the wrong order. You have to create the button before binding it:

···

Am Freitag, 20. Juni 2014 19:06:53 UTC+2 schrieb Ben Carson:

self.go = wx.Button(self,-1, label = ‘Go!’, pos = (110, 325))
self.go.Bind(wx.EVT_BUTTON, self.Generate)

Hi Ben,

···

On 6/20/2014 19:06, Ben Carson wrote:

#Assume the indentation in the code is right (but you can still ask to check with me), it isn't fommating this nicely
I'm working on making a bind event on a button refer to a function, however i get the error explained in the title.

Please attach the code instead of copying it inline. It is also most of the time much quicker for someone to help you if the code is self contained and can be run without installing anything.

Well explained here:
http://wiki.wxpython.org/MakingSampleApps

Werner

The first thing that stands out to me has pretty much already been addressed. Your bindings should always come after the widget is created. It is hard to bind an action to a button that does not exist yet. I personally put my bindings at the end of my init and if I have more than a few I place them in a function and call said function at the end of the init this way I keep my code a bit more tidy and the binds are easy to find.

Also as Werner pointed out, it is best to “slim down” the code you post here to the smallest possible example that still exhibits the error. Then attach the example to your post instead of pasting the code within it.

In short, please read Werner’s reply, and moving the line binding your event to your button so that it is called after the button is created should resolve your issue.