title: PyQt5 Retrieve Folder Directory and Set It in lineEdit
body: <p>Need some advice on how to retrieve the directory path for a selected folder and set it on the LineEdit.</p>
  
  <p>I have the following simple GUI
  <a href="https://i.stack.imgur.com/h0PgZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h0PgZ.png" alt="enter image description here"></a></p>
  
  <p>If I clicked the toolButton (the button inside the red-circle), then a dialog window would pop up. Then we could navigate to select the desired folder. I wish that I could pass the path (in string) to the selected folder to the lineEdit box next to the button, once the user clicks Select Folder. However, I could not figure out how to do that. So far here is my code:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  class Ui_TestQFileDialog(object):
      def _open_file_dialog(self): # a function to open the dialog window
          result = str(QtWidgets.QFileDialog.getExistingDirectory())
          print(result)
          return result
  
      def setupUi(self, TestQFileDialog):
          TestQFileDialog.setObjectName("TestQFileDialog")
          TestQFileDialog.resize(240, 320)
  
          self.toolButtonOpenDialog = QtWidgets.QToolButton(TestQFileDialog)
          self.toolButtonOpenDialog.setGeometry(QtCore.QRect(210, 10, 25, 19))
          self.toolButtonOpenDialog.setObjectName("toolButtonOpenDialog")
          directory = self.toolButtonOpenDialog.clicked.connect(self._open_file_dialog)
  
          self.lineEdit = QtWidgets.QLineEdit(TestQFileDialog)
          self.lineEdit.setEnabled(False)
          self.lineEdit.setGeometry(QtCore.QRect(10, 10, 191, 20))
          self.lineEdit.setObjectName("lineEdit")
          self.lineEdit.setText('{}'.format(directory))
  
          self.retranslateUi(TestQFileDialog)
          QtCore.QMetaObject.connectSlotsByName(TestQFileDialog)
  
      def retranslateUi(self, TestQFileDialog):
          _translate = QtCore.QCoreApplication.translate
          TestQFileDialog.setWindowTitle(_translate("TestQFileDialog", "Dialog"))
          self.toolButtonOpenDialog.setText(_translate("TestQFileDialog", "..."))
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      TestQFileDialog = QtWidgets.QDialog()
      ui = Ui_TestQFileDialog()
      ui.setupUi(TestQFileDialog)
      TestQFileDialog.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Tried to include print in the _open_file_dialog function, and it printed the directory path. However, it was not returned and kept in the directory variable.</p>
  
  <p>Any advice will be much appreciated.</p>
  
  <p>Thanks and regards,</p>
  
  <p>Arnold</p>