(MainWindow)对象没有属性(go)[WxPython]

时间:2014-06-20 15:15:59

标签: python wxpython

我正在努力在按钮上创建绑定事件引用一个函数,但是我得到了标题中解释的错误。

我已经有另一个绑定事件正在工作和编码,据我所知,两个语法之间没有区别。

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()

因此,您可以看到def updateList缩进与def Generate相同。它也具有相同的参数和相同的绑定事件语法,除了一个是单选按钮而另一个是按钮。我做错了什么?

1 个答案:

答案 0 :(得分:1)

在将wx.Button指定给self.go之前,您在绑定到self.go,在创建按钮后移动绑定。