title: how to pass the self between 2 windows using modules
body: <p>I'm learning Python, version 3.7 with PyQT5 (Qt Designer)</p>
  <p>I'm trying to define the value of a label using modules, in window 1 it calls the function and it works, but when I open window 2 and click the button it triggers the function but passes the self of the current window (window 2) where there is no label , generating the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;\template\config.py&quot;, line 18, in returnMain
      fun1(self)
    File &quot;\modulos\functions.py&quot;, line 7, in fun1
      lbl = int(self.ui.lblTest.text())
  AttributeError: 'Ui_window2' object has no attribute 'lblTest'
  Preciso que ele use na função o self da window 1.
  </code></pre>
  <p>I replicated the error in small files, it works until you click the button in the second window that gives the described error.</p>
  <p>Here is the structure of the codes in the directory:</p>
  <p><a href="https://i.stack.imgur.com/Vm445.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vm445.png" alt="enter image description here" /></a></p>
  <p>Follow the files.</p>
  <p><strong>run.py (Used to start the program)</strong></p>
  <pre><code>   from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
      import sys
      
      from template.main import MainScreen
      
      if __name__ == &quot;__main__&quot;:
          app = QApplication(sys.argv)
          main = MainScreen()
          main.show()
          sys.exit(app.exec_())
  </code></pre>
  <p><strong>gui/window1.py (janela principal)</strong></p>
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  class Ui_window1(object):
      def setupUi(self, win1):
          win1.setObjectName(&quot;win1&quot;)
          win1.resize(297, 219)
          self.centralwidget = QtWidgets.QWidget(win1)
          self.centralwidget.setObjectName(&quot;centralwidget&quot;)
          self.btnConfig = QtWidgets.QPushButton(self.centralwidget)
          self.btnConfig.setGeometry(QtCore.QRect(110, 150, 75, 23))
          self.btnConfig.setObjectName(&quot;btnConfig&quot;)
          self.lblTest = QtWidgets.QLabel(self.centralwidget)
          self.lblTest.setGeometry(QtCore.QRect(120, 70, 47, 13))
          self.lblTest.setObjectName(&quot;lblTest&quot;)
          win1.setCentralWidget(self.centralwidget)
  
          self.retranslateUi(win1)
          QtCore.QMetaObject.connectSlotsByName(win1)
  
      def retranslateUi(self, win1):
          _translate = QtCore.QCoreApplication.translate
          win1.setWindowTitle(_translate(&quot;win1&quot;, &quot;Window 1&quot;))
          self.btnConfig.setText(_translate(&quot;win1&quot;, &quot;Open config&quot;))
          self.lblTest.setText(_translate(&quot;win1&quot;, &quot;0&quot;))
  </code></pre>
  <p><strong>gui/window2.py (settings window)</strong></p>
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  class Ui_window2(object):
      def setupUi(self, win2):
          win2.setObjectName(&quot;win2&quot;)
          win2.resize(222, 241)
          self.centralwidget = QtWidgets.QWidget(win2)
          self.centralwidget.setObjectName(&quot;centralwidget&quot;)
          self.btnReturn = QtWidgets.QPushButton(self.centralwidget)
          self.btnReturn.setGeometry(QtCore.QRect(70, 120, 75, 23))
          self.btnReturn.setObjectName(&quot;btnReturn&quot;)
          win2.setCentralWidget(self.centralwidget)
  
          self.retranslateUi(win2)
          QtCore.QMetaObject.connectSlotsByName(win2)
  
      def retranslateUi(self, win2):
          _translate = QtCore.QCoreApplication.translate
          win2.setWindowTitle(_translate(&quot;win2&quot;, &quot;Window 2&quot;))
          self.btnReturn.setText(_translate(&quot;win2&quot;, &quot;Return Main&quot;))
  </code></pre>
  <p><strong>modulos/functions.py (where will the functions be)</strong></p>
  <pre><code>from PyQt5.QtWidgets import *
  from template import main
  
  def fun1(self):
      lbl = int(self.ui.lblTest.text())
      lbl = (lbl+1)
      self.ui.lblTest.setText(str(lbl))
  </code></pre>
  <p><strong>template/config.py (where I will handle the settings)</strong></p>
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  from PyQt5.QtWidgets import *
  from gui.window2 import *
  from modulos.functions import fun1
  
  class ConfigScreen(QMainWindow):
     
      def __init__(self,*args,**argsv):        
          super(ConfigScreen,self).__init__(*args,**argsv)
          self.ui = Ui_window2()
          self.ui.setupUi(self)
          self.ui.btnReturn.clicked.connect(self.returnMain)
  
      def returnMain(self):
          fun1(self)
          self.close()
  </code></pre>
  <p><strong>template/main.py (main program module)</strong></p>
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  from PyQt5.QtWidgets import *
  from gui.window1 import *
  from template.config import ConfigScreen
  from modulos.functions import fun1
  
  class MainScreen(QMainWindow):
     
      def __init__(self,*args,**argsv):        
          super(MainScreen,self).__init__(*args,**argsv)
          self.ui = Ui_window1()
          self.ui.setupUi(self)
          self.ui.btnConfig.clicked.connect(self.openConfig)
  
          fun1(self)
  
      def openConfig(self):        
          self.config = ConfigScreen()
          self.config.show()
  </code></pre>