python - using entry from a class in another classes function -


the variable function given via class functionframe. when trying use in add_function error.

attributeerror: class functionframe has no attribute 'function'

class functionframe(frame):     """a simple application allow user ti enter     expressio     n , evaluate     """     def __init__(self, master):         """         a=simple expression evaluator         """         frame.__init__(self, master, relief=sunken, bg='#a5a5a5', pady=3)         label(self, text='function in x: ', bg='#a5a5a5').pack(side=left)         function = entry(self, width=35).pack(side=left, padx=2)         button(self, text='select', command=self.select).pack(side=right, padx=4)         colour = entry(self, width=15).pack(side=right)         label(self, text='function colour: ', bg='#a5a5a5').pack(side=right, padx=2)      def select(self):         (rgb, hx)= askcolor()  class buttonframe(frame):     """a simple application allow user ti enter     expression , evaluate     """     def __init__(self, master):         """         a=simple expression evaluator         """         frame.__init__(self, master, bg='#cecef6')         button(self, text='add function', command=self.add_function).pack(side=left)         button(self, text='redraw all', command=self.redraw_all).pack(side=left)         button(self, text='remove last function', command=self.remove_last).pack(side=left)         button(self, text='remove functions', command=self.remove_all).pack(side=left)         button(self, text='exit', command=self.exit_app).pack(side=left)       def add_function(self):         make_function(functionframe.function) 

function defined local variable inside __init__:

def __init__(self, master):     function = entry(self, width=35).pack(side=left, padx=2) 

to use function outside of __init__, you'll need make instance attribute instead:

def __init__(self, master):     self.function = entry(self, width=35).pack(side=left, padx=2) 

then, in buttonframe, you'll need make instance of functionframe:

def add_function(self):     make_function(functionframe(self).function) 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -