PDA

View Full Version : QFileDialog.getOpenFileNames crashes the interpreter



pfeldman
7th November 2020, 23:44
I'm using PyQt5 and attempting to create a dialog that allows the user to select one or more files.

The following code functions but allows the user to select only a single file:

fname, _= QFileDialog.getOpenFileName(parent=self, directory=folder, caption='Select a file')

If I try to use `getOpenFileNames` instead of `getOpenFileName`, the interpreter crashes. Please advise.

ChrisW67
8th November 2020, 04:49
If I try to use `getOpenFileNames` instead of `getOpenFileName`, the interpreter crashes. Please advise.
How does it crash, because it certainly does not here.

d_stranz
8th November 2020, 22:06
fname, _= QFileDialog.getOpenFileName(parent=self, directory=folder, caption='Select a file')

Why the ",_" ? getOpenFileName() (or getOpenFileNames()) only returns a single value, either a QString or a QStringList.