1

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_()
4

1 回答 1

3

在您实际运行对话框之前,不会有任何选定的文件。

if dialog.exec_():
    fileNames = dialog.selectedFiles()
    print str(fileNames)
else:
    print "Canceled"
于 2014-04-23T15:40:20.533 回答