I have a block of code that opens a QFileDialog using Python3 and PyQt5:
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog
import sys
class MCVE(QWidget):
def __init__(self):
super().__init__()
self.initialize()
def initialize(self):
self.setWindowTitle('MCVE')
self.setGeometry(50, 50, 400, 200)
btn = QPushButton('Example', self)
btn.clicked.connect(self.clicked)
self.show()
def clicked(self):
filename = QFileDialog.getOpenFileName(
self, "Open Template", "c:",
"Templates (*.xml);;All Files (*.*)")
print(filename)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MCVE()
sys.exit(app.exec_())
In Python 2 using PyQt4 the print(filename) statement, after pressing the cancel button, outputs as an empty string. When I run the same code in Python 3 using PyQt5 I get:
('', '')
NOTE: The quotes are Single Quotes
Can someone explain what is going on? I couldn't find anything under the documentation between PyQt4 and PyQt5. I know that strings changed between Python 2 and Python 3, but I'm not sure those changes would cause an issue like this. Thanks!
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…