title: accessing UI elements from another class in python
body: <p>Example</p>
  
  <p>function.py</p>
  
  <pre><code>class testClass(object):
      def functionA(self):
          #doSomething
          self.Qlabel.clear()
  </code></pre>
  
  <p>main.py</p>
  
  <pre><code>class mainClass(object):
      def __init__(self, parent = #something):
          #initialize something
  
          super(mainClass, self).__init__(parent)
          self.setupUi(self)
          self.Qlabel.clicked.connect(self.testFunc)
  
  
      def testFunc(self):
  
          import function as FT
          FT.testClass().functionA(self)
  </code></pre>
  
  <p>I tried connecting my PyQt <code>function.py</code> to <code>main.py</code>. It keeps giving me this TypeError: functionA() takes exactly 1 argument (2 given). </p>
  
  <p>If I take away the 'self' in so that it's <code>FT.testClass().functionA()</code>, then I get AttributeError: 'testClass' object has no attribute 'Qlabel'</p>
  
  <p>I saw in <a href="https://stackoverflow.com/questions/36709603/pyqt-accessing-elements-from-outside-the-class">PyQt : accessing elements from outside the class</a> that it works with just using <code>obj</code> but not with classes.</p>
  
  <p>I would like to understand how to fix this and also why my previous method doesn't work. Any help would be appreciated!</p>