python - variable not being defined in a class despite being defined in it's init function -


from wx import * import customer c  class customermain ( wx.frame ):          def __init__( self, parent ):             wx.frame.__init__ ( self, parent, id = wx.id_any, title = u"customers", pos = wx.defaultposition, size = wx.size( 517,486 ), style = wx.default_frame_style|wx.tab_traversal )              self.setsizehintssz( wx.size( -1,-1 ), wx.defaultsize )              bsizer3 = wx.boxsizer( wx.vertical )               # create customer             self.cust = c.customer()              self.list = wx.listctrl( self, wx.id_any, wx.defaultposition, wx.defaultsize, wx.lc_icon )             self.list.insertcolumn(0,'id', width = 140)             self.list.insertcolumn(1,'first name', width = 140)             self.list.insertcolumn(2,'last name', width = 140)             self.list.setminsize( wx.size( 500,300 ) )             self.list.setmaxsize( wx.size( 1000,800 ) )                bsizer3.add( self.list, 0, wx.all|wx.align_center_horizontal, 5 )              bsizer4 = wx.boxsizer( wx.horizontal )              self.m_button20 = wx.button( self, wx.id_any, u"add customer", wx.defaultposition, wx.defaultsize, 0 )             self.m_button20.bind(wx.evt_button, self.add_entry)             bsizer4.add( self.m_button20, 1, wx.all|wx.align_center_vertical, 5 )              self.m_button21 = wx.button( self, wx.id_any, u"update record", wx.defaultposition, wx.defaultsize, 0 )             self.m_button21.bind(wx.evt_button, self.add_entry)             self.refresh_list(none)             bsizer4.add( self.m_button21, 1, wx.align_center_vertical|wx.all, 5 )              bsizer3.add( bsizer4, 1, wx.expand, 5 )              self.setsizer( bsizer3 )             self.layout()              self.centre( wx.both )             self.show()          def refresh_list(self, event):             """place names of each customerentry list"""              index =0             self.entrydict = {}             entry in self.cust.list_entries():                 self.list.insertstringitem(index,entry.cust_id)                 self.list.setstringitem(index,1,entry.l_name)                 self.list.setstringitem(index,2,entry.f_name)                 index += 1  ##            self.list.refreshitems(self)         def add_entry(self, event):            """add new entry address cust"""            # start out blank, generic customerentry            entry = c.customerentry("", "", "", "","" )            self.endiag = customerdetail(self , entry)            self.endiag.show()             # got details in new_entry, add            self.cust.add_entry(entry.cust_id,entry.f_name, entry.l_name, entry.address,entry.cust_stat)  ##           self.refresh_list()          def show_detail(self, event):            e_id = int(self.list.curselection()[0])            entry = self.cust.list_entries()[e_id]            customerdetail(entry)            self.refresh_list()  def __del__( self ):     pass   class customerdetail ( wx.dialog ):          def __init__( self, parent,entry ):                 wx.dialog.__init__ ( self, parent, id = wx.id_any, title = wx.emptystring, pos = wx.defaultposition, size = wx.size( 690,500 ), style = wx.default_dialog_style )                  self.setsizehintssz( wx.size( 500,500 ), wx.defaultsize )                  bsizer6 = wx.boxsizer( wx.vertical )                  gsizer6 = wx.gridsizer( 2, 2, 0, 0 )                  self.m_statictext5 = wx.statictext( self, wx.id_any, u"id", wx.defaultposition, wx.defaultsize, 0 )                 self.m_statictext5.wrap( -1 )                 gsizer6.add( self.m_statictext5, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )                  self.cust_id = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )                 self.cust_id.setminsize( wx.size( 200,15 ) )                 self.cust_id.setmaxsize( wx.size( 500,15 ) )                  gsizer6.add( self.cust_id, 1, wx.align_center_horizontal|wx.align_center_vertical|wx.all|wx.expand, 5 )                  self.m_statictext6 = wx.statictext( self, wx.id_any, u"first name", wx.defaultposition, wx.defaultsize, 0 )                 self.m_statictext6.wrap( -1 )                 gsizer6.add( self.m_statictext6, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )                  self.f_name = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )                 self.f_name.setminsize( wx.size( 200,15 ) )                 self.f_name.setmaxsize( wx.size( 500,15 ) )                  gsizer6.add( self.f_name, 0, wx.all|wx.align_center_vertical|wx.align_center_horizontal|wx.expand, 5 )                  self.m_statictext7 = wx.statictext( self, wx.id_any, u"last name", wx.defaultposition, wx.defaultsize, 0 )                 self.m_statictext7.wrap( -1 )                 gsizer6.add( self.m_statictext7, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )                  self.l_name = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )                 self.l_name.setminsize( wx.size( 200,15 ) )                 self.l_name.setmaxsize( wx.size( 500,15 ) )                  gsizer6.add( self.l_name, 0, wx.all|wx.align_center_horizontal|wx.expand|wx.align_center_vertical, 5 )                  self.m_statictext8 = wx.statictext( self, wx.id_any, u"address", wx.defaultposition, wx.defaultsize, 0 )                 self.m_statictext8.wrap( -1 )                 gsizer6.add( self.m_statictext8, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )                  self.address = wx.textctrl( self, wx.id_any, wx.emptystring, wx.defaultposition, wx.defaultsize, 0 )                 self.address.setminsize( wx.size( 200,15 ) )                 self.address.setmaxsize( wx.size( 500,15 ) )                  gsizer6.add( self.address, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical|wx.expand, 5 )                  self.m_statictext12 = wx.statictext( self, wx.id_any, u"status", wx.defaultposition, wx.defaultsize, 0 )                 self.m_statictext12.wrap( -1 )                 gsizer6.add( self.m_statictext12, 0, wx.all|wx.align_center_horizontal|wx.align_center_vertical, 5 )                   stat_choices = ["active","inactive","archived"]                  self.cust_stat = wx.combobox( self, wx.id_any, u"select option!", wx.defaultposition, wx.defaultsize, stat_choices, 0 )                 self.cust_stat.setminsize( wx.size( 200,15 ) )                 self.cust_stat.setmaxsize( wx.size( 300,15 ) )                 self.cust_stat.bind(wx.evt_combobox, self.onselect)                 gsizer6.add( self.cust_stat, 0, wx.all, 5 )                  bsizer6.add( gsizer6, 1, wx.expand, 5 )                  bsizer13 = wx.boxsizer( wx.horizontal )                  self.m_button24 = wx.button( self, wx.id_any, u"ok", wx.defaultposition, wx.defaultsize, 0 )                 self.m_button24.bind(wx.evt_button, self.ok)                  bsizer13.add( self.m_button24, 1, wx.all|wx.align_center_vertical, 5 )                  self.m_button25 = wx.button( self, wx.id_any, u"cancel", wx.defaultposition, wx.defaultsize, 0 )                 self.m_button25.bind(wx.evt_close, self.closedial)                  bsizer13.add( self.m_button25, 1, wx.all|wx.align_center_vertical, 5 )                  bsizer6.add( bsizer13, 1, wx.expand, 5 )                  self.setsizer( bsizer6 )                 self.layout()                  self.centre( wx.both )          def onselect (self, event):             self.cust_stat.getvalue()          def closedial(self,event):                 self.destroy()           def ok(self, event):             self.entry.set_details( str(self.cust_id.get()),                                 str(self.f_name.get()),                                 str(self.l_name.get()),                                 str(self.address.get()),                                 str(self.cust_stat.get()) )             self.closedial          def __del__( self ):                 pass                 def main():      ex = wx.app()     customermain(none)     ex.mainloop()       if __name__ == '__main__':     main() 

so given code above in customerdetail dialog... @ ok function. tries call entry reference customer.py set_details found. thing claims not defined in class despite me setting in init function , defining handler customer object... ideas?

traceback

traceback (most recent call last): file "c:\users\owner\desktop\sad prog\customer_app.py", line 173, in ok      self.entry.set_details( str(self.cust_id.get()), attributeerror: 'customerdetail' object has no attribute 'entry'  

it looks passed in entry parameter customerdetail.__init__, didn't set on object.

you'll need this...

class customerdetail ( wx.dialog ):     def __init__( self, parent,entry ):         wx.dialog.__init__ ( self, parent, id = wx.id_any, title = wx.emptystring, pos = wx.defaultposition, size = wx.size( 690,500 ), style = wx.default_dialog_style )         self.entry = entry         # <rest of code here> 

...to store variable class attribute, otherwise it'll go out of scope when __init__ method ends.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -