Get multiple file names (PyQT/PySide)

vegaseat 3 Tallied Votes 3K Views Share

A simple test of PySide's QFileDialog widget and its method getOpenFileNames. Use method getOpenFileName if you want just one file name.

''' ps_test_QFileDialog2.py
a very simple template to test PySide widgets ...

get a list of full path multiple filenames via
QFileDialog.getOpenFileNames()
(press ctrl key or shift key when selecting multiple files)

for Python33 you can use the Windows self-extracting installer
PySide-1.1.2qt483.win32-py3.3.exe
from:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
also:
http://qt-project.org/wiki/PySide_Binaries_Windows
PySide is the official LGPL-licensed version of PyQT

Tested with Python27 and Python33  by   vegaseat  16apr2013
'''

from PySide.QtCore import *
from PySide.QtGui import *

# replace [] with sys.argv for commandline
app = QApplication([])

# ----- start your widget test code ----

caption = 'Open file'
# use current/working directory
directory = './'
filter_mask = "Python/Text files (*.py *.pyw *.txt)"
filenames = QFileDialog.getOpenFileNames(None,
    caption, directory, filter_mask)[0]

print(filenames)  # test

# ---- end of widget test code -----

# for this case ...
app.processEvents()
#app.exec_()