I am now learning pyQT and I would like to do something that is presumably not difficult, but for which I could not find any satisfactory answer on the internet : Create a function using pyQT5 that just opens the standard file dialog of Windows or Ubuntu from iPython and returns the filepath (and filename).

My first attempts from tutorials found online ( https://www.tutorialspoint.com/pyqt/pyqt_qfiledialog_widget.htm ) were not successful. It looks something like:

from PyQt5.QtWidgets import (QMainWindow, QTextEdit, 
    QAction, QFileDialog, QApplication)
from PyQt5.QtGui import QIcon

def test_dialog():
    dlg = QFileDialog()
    if dlg.exec_():
        filenames = dlg.selectedFiles()
        return filenames

if __name__ == '__main__':

I use the latest versions of anaconda distribution with Python 3.7.3 and pyQT 5.9.2 .

0 Answers