-2
file = QtWidgets.QFileDialog.getOpenFileName()

I have used the above to get the path of a file. The output is:

('D:/test images/test13.jpg', '')

What should i do to get the output as: 'D:/test images/test13.jpg'?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Shreya Gaddam
  • 33
  • 1
  • 8
  • Possible duplicate of [Getting one value from a python tuple](http://stackoverflow.com/questions/3136059/getting-one-value-from-a-python-tuple) – SiHa Jun 13 '16 at 11:30
  • Even if you didn't know this was a tuple, a title like "Get only path of file from QFileDialog.getOpenFileName" would be much better than "Python GUI PyQt". – The Compiler Jun 14 '16 at 07:08

1 Answers1

1

QFileDialog.getOpenFileName() in PyQt5 is the same as QFileDialog.getOpenFileNameAndFilter() in PyQt4, it returns the file name and the filter selected by the user. You can use

file = QtWidgets.QFileDialog.getOpenFileName()[0]

to get only the file, or

file, filter = QtWidgets.QFileDialog.getOpenFileName()

which I find clearer because it's immediately obvious what the method returns.

mata
  • 67,110
  • 10
  • 163
  • 162