Prev: simple integer subclass
Next: simple (I hope!) problem
From: Chris Hare on 2 Aug 2010 20:06 What I am trying to do is call a class function from a menu, for example displaySubMenu.add_radiobutton(label="Medium", variable=radarPanelSize, command=radarWidgets.refresh) class radarWidgets: def __init__(self,root): self.window = root def refresh(self): global radar global refreshTimer self.refreshTimer.cancel() logging.debug("handlesRadarRefreshByTimer()") # # destroy the existing frame the radar is in # self.w.destroy() self.lblLastUpdate.destroy() self.btnRefresh.destroy() # # rebuild the radarWidgets # self.createImage() self.refreshTimer = threading.Timer( 900, self.refresh) self.refreshTimer.start() This doesn't work because the instance of radarWidgets was defined in a different class ...... class mainDisplay: def __init__(self,root): self.window = root def show(self): # # Configure the base frame # base=Frame(self.window,bg=backColor,width=1200, height=800) base.grid() frameRadar = Frame(base, bd=0, bg=backColor) frameRadar.grid(row=2,column=1,sticky=N+E+S+W) # radar = radarWidgets(frameRadar) radar.show() so the actual instance is called "radar". If I put the instance name in the menu item, I get an error that "radar" is unknown. If I use RadarWidgets.refresh ins the command for the menu, I get the error: TypeError: unbound method refresh() must be called with radarWidgets instance as first argument (got nothing instead) Any ideas? Thanks!
From: rantingrick on 2 Aug 2010 23:31 Chris, It looks as if you are calling a class object and not an instance object. However i cannot be for sure because you are using improper Python style. All classes should be capwords. But here again you have used camelcase for the class identifiers "radarWidgets" and "mainDisplay", which is bad bad bad!! You been asking multiple questions about this code for the last couple of days (and thats fine). However, maybe you would do everyone a favor by posting the entire code so we can offer suggestions. Just seeing seeing a snipit here and a snipit there is not helping because we don't know where else you may be screwing up that we cannot see. It seems you're committing many faux pas with not only your coding style but also your coding practices. I've seen overuse of globals and bad styles and on and on. So post the entire code so myself and others can go through this mess and get it sorted out. If you keep on with your bad habits you're never going to become proficient with Python. I am sorry if this post seems condescending because that is not the case.
From: Chris Hare on 3 Aug 2010 07:19 No offense taken. I'll get getting the Google Python Style Guide today. I'll package up the code tonight and it to the group. Fortunately ( or unfortunately), it is all in one file right now. On Aug 2, 2010, at 10:31 PM, rantingrick wrote: > > Chris, > > It looks as if you are calling a class object and not an instance > object. However i cannot be for sure because you are using improper > Python style. All classes should be capwords. But here again you have > used camelcase for the class identifiers "radarWidgets" and > "mainDisplay", which is bad bad bad!! > > You been asking multiple questions about this code for the last couple > of days (and thats fine). However, maybe you would do everyone a favor > by posting the entire code so we can offer suggestions. Just seeing > seeing a snipit here and a snipit there is not helping because we > don't know where else you may be screwing up that we cannot see. > > It seems you're committing many faux pas with not only your coding > style but also your coding practices. I've seen overuse of globals and > bad styles and on and on. So post the entire code so myself and others > can go through this mess and get it sorted out. If you keep on with > your bad habits you're never going to become proficient with Python. > > I am sorry if this post seems condescending because that is not the > case. > -- > http://mail.python.org/mailman/listinfo/python-list
From: Chris Hare on 3 Aug 2010 07:30 Oh and Risk, I know I was calling the class object. class 1 creates the instance object class 2 tries to use the instance object so the problem is how to make class 2 knowledgable of instance object? I guess I could pass the instance object into the class, since class1 creates the instance and also calls class 2. On Aug 2, 2010, at 10:31 PM, rantingrick wrote: > > Chris, > > It looks as if you are calling a class object and not an instance > object. However i cannot be for sure because you are using improper > Python style. All classes should be capwords. But here again you have > used camelcase for the class identifiers "radarWidgets" and > "mainDisplay", which is bad bad bad!! > > You been asking multiple questions about this code for the last couple > of days (and thats fine). However, maybe you would do everyone a favor > by posting the entire code so we can offer suggestions. Just seeing > seeing a snipit here and a snipit there is not helping because we > don't know where else you may be screwing up that we cannot see. > > It seems you're committing many faux pas with not only your coding > style but also your coding practices. I've seen overuse of globals and > bad styles and on and on. So post the entire code so myself and others > can go through this mess and get it sorted out. If you keep on with > your bad habits you're never going to become proficient with Python. > > I am sorry if this post seems condescending because that is not the > case. > -- > http://mail.python.org/mailman/listinfo/python-list
|
Pages: 1 Prev: simple integer subclass Next: simple (I hope!) problem |