title: How to call main-window method from a dialog
body: <p>I have the following dialog with my new keyword "stackoverflow":</p>
  
  <p><a href="https://i.stack.imgur.com/wRuL2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wRuL2.png" alt="Example Dialog"></a></p>
  
  <p>After pressing the "hinzufügen" button the following method is called:</p>
  
  <pre><code>keywords = self.wort_neue_woerter.toPlainText()
  try:
      with open("files/schluesselwoerter.txt", 'r') as file:
          output = file.read()
          self.keywords += output
  except:
      print("Datei nicht gefunden")
  with open("files/schluesselwoerter.txt", 'w') as file:
      file.write(self.keywords)
  print("Ausgeführt")
  </code></pre>
  
  <p>Every keyword is written in the "schlüsselwoerter.txt" file:</p>
  
  <p><a href="https://i.stack.imgur.com/FqalX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FqalX.png" alt="schluesselwoerter.txt"></a></p>
  
  <p>The method from the first dialog uses this textfile to populate the ListWidget.</p>
  
  <p><a href="https://i.stack.imgur.com/zs3TK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zs3TK.png" alt="Dialog 1"></a></p>
  
  <pre><code>with open('files/schluesselwoerter.txt', 'r') as file:
  output = file.read()
  output_list = output.split(',')
  for element in output_list:
      item = QtWidgets.QListWidgetItem(element.strip())
      self.wort_uebersicht.addItem(item)
  </code></pre>
  
  <p>I want to call the Dialog 1 method <code>populate_listWidget</code> right after pressing on the button in Dialog 2. How can i do this?</p>
  
  <p>Here is the full code:</p>
  
  <p>Main Class:</p>
  
  <pre><code>import sys
  import main_window
  from PyQt5 import QtWidgets
  
  class GUI(QtWidgets.QMainWindow, main_window.Ui_MainWindow):
      def __init__(self):
          super().__init__()
          self.setupUi(self)
  
  if __name__ == '__main__':
      app = QtWidgets.QApplication(sys.argv)
      gui = GUI()
      gui.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Main_Window:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  import dialog
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(800, 600)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
          self.horizontalLayout.setObjectName("horizontalLayout")
          self.listWidget = QtWidgets.QListWidget(self.centralwidget)
          self.listWidget.setObjectName("listWidget")
          self.horizontalLayout.addWidget(self.listWidget)
          self.main_insert_btn = QtWidgets.QPushButton(self.centralwidget)
          self.main_insert_btn.setObjectName("main_insert_btn")
          self.horizontalLayout.addWidget(self.main_insert_btn)
          MainWindow.setCentralWidget(self.centralwidget)
          self.menubar = QtWidgets.QMenuBar(MainWindow)
          self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
          self.menubar.setObjectName("menubar")
          MainWindow.setMenuBar(self.menubar)
          self.statusbar = QtWidgets.QStatusBar(MainWindow)
          self.statusbar.setObjectName("statusbar")
          MainWindow.setStatusBar(self.statusbar)
  
          try:
              self.populate_list()
          except:
              print("Population failed")
  
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
          self.main_insert_btn.clicked.connect(self.create_new_keywords)
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
          self.main_insert_btn.setText(_translate("MainWindow", "Insert"))
  
      def create_new_keywords(self):
          keyword_dialog = QtWidgets.QDialog()
          keyword_dialog.ui = dialog.Ui_Dialog()
          keyword_dialog.ui.setupUi(keyword_dialog)
          keyword_dialog.exec_()
  
      def populate_list(self):
          with open('schluesselwoerter.txt', 'r') as file:
              output = file.read()
              output_list = output.split(',')
              for element in output_list:
                  item = QtWidgets.QListWidgetItem(element.strip())
                  self.listWidget.addItem(item)
  </code></pre>
  
  <p>Insert Dialog:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  class Ui_Dialog(object):
      def setupUi(self, Dialog):
          Dialog.setObjectName("Dialog")
          Dialog.resize(400, 300)
          self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
          self.verticalLayout.setObjectName("verticalLayout")
          self.text_input = QtWidgets.QPlainTextEdit(Dialog)
          self.text_input.setObjectName("text_input")
          self.verticalLayout.addWidget(self.text_input)
          self.insert_btn = QtWidgets.QPushButton(Dialog)
          self.insert_btn.setObjectName("insert_btn")
          self.verticalLayout.addWidget(self.insert_btn)
  
          self.retranslateUi(Dialog)
          QtCore.QMetaObject.connectSlotsByName(Dialog)
  
          self.insert_btn.clicked.connect(self.create_new_entry)
  
      def retranslateUi(self, Dialog):
          _translate = QtCore.QCoreApplication.translate
          Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
          self.insert_btn.setText(_translate("Dialog", "Insert"))
  
      def create_new_entry(self):
          keywords = self.text_input.toPlainText()
          try:
              with open("schluesselwoerter.txt", 'r') as file:
                  output = file.read()
                  keywords += output
          except:
              print("Datei nicht gefunden")
          with open("schluesselwoerter.txt", 'w') as file:
              file.write(keywords)
          print("Ausgeführt")
          self.text_input.setPlainText("")
  </code></pre>