how to have a directory dialog in Pyqt

2019-02-02 21:08发布

问题:

How to have a file dialog that select only directories not files in PyQt?

And how do I retrieve the name of the selected directory?

回答1:

From inside your QDialog/QWidget class, you should be able to do:

file = str(QFileDialog.getExistingDirectory(self, "Select Directory"))