Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt - How to open a directory folder?

Tags:

python

pyqt

pyqt4

I have searched a lot and I know how to open a directory dialog window. But what I am looking for is the method to open a directory folder under windows OS, just like you right click one of your local folder and select open.

Any suggestions?

like image 583
icy Avatar asked Nov 28 '22 01:11

icy


2 Answers

Try this:

dir_ = QtGui.QFileDialog.getExistingDirectory(None, 'Select a folder:', 'C:\\', QtGui.QFileDialog.ShowDirsOnly)

If the user hits cancel, then dir_ is empty.

like image 106
mont_ Avatar answered Dec 05 '22 18:12

mont_


For python 3.7 you can just do:

os.startfile(path)
like image 32
mmdfan Avatar answered Dec 05 '22 19:12

mmdfan