Question

When I run the script below, I am able to select several files in the file dialog, but the value returned for the var "filenames" is: "[ ]", which appears to be an empty list.

I think the solution must be somewhere on this page, but I can't figure out what it is: http://srinikom.github.io/pyside-docs/PySide/QtGui/QFileDialog.html

Any suggestions would be much appreciated. I'm a python and pyside newbie.

#!/usr/bin/python
# -*- coding: utf-8 -*-
# http://srinikom.github.io/pyside-docs/PySide/QtGui/QFileDialog.html

from PySide import QtGui
app = QtGui.QApplication([])
dialog = QtGui.QFileDialog()
dialog.setFileMode(QtGui.QFileDialog.ExistingFiles)
#dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
dialog.setOption(QtGui.QFileDialog.ShowDirsOnly, False)
fileNames = dialog.selectedFiles()
print str(fileNames)
dialog.exec_()
Was it helpful?

Solution

There won't be any selected files before you actually run the dialog.

if dialog.exec_():
    fileNames = dialog.selectedFiles()
    print str(fileNames)
else:
    print "Canceled"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top