title: Tying two variables together in Python
body: <p>I understand that in Python variables point to objects so when you assign one to another they then both point to the same object. What I'd like to do is to make one variable change when the other one does. In the case I am working on a GUI. So I have a label with an attribute for its text. I'd like that attribute to be equal to an attribute in another class. At the moment I am doing it by using an intermediate function but it feels like there should be a more elegant way of doing it. So my way is effectively similar to the below:</p>
  
  <pre><code>class Label():
      def init():
          self.text = None
          self.gettext = None
  
      def display():
          if callable(self.gettext):
              self.text = self.gettext()
          else:
              self.text = self.gettext
          print(str(self.text))
  
  class Anotherclass():
      def init():
          self.anattribute = "avaluethatchanges"    
  
  mylabel = Label()
  myclass = Anotherclass()
  
  def gettheattribute():
      return myclass.anattribute
  
  mylabel.gettext = gettheattribute
  </code></pre>
  
  <p>There will be lots of labels linked to lots of different classes. So what I would like to be able to do is just:</p>
  
  <pre><code>mylabel.gettext = myclass.anattribute
  </code></pre>
  
  <p>However, when myclass.anattribute gets changed - myclass.gettext doesn't. I understand why but is there another way of writing it so that it does - without creating the function?</p>
  
  <p>Many thanks</p>
  
  <p>EDIT: - Both classes will be used in other applications where one or the other might not exist so I can't hard code the relationship between them within the classes themselves.</p>