我有一个带上传按钮的主窗口,点击上传按钮后,QFileDialog会打开以上传文件。 如何在选择文件并单击上传对话框中的打开按钮后启用弹出窗口?
我尝试了这个,但它关闭了程序
def App(Qwidget, self):
w = QWidget()
w.resize(320, 240)
QFileDialog.getOpenFileNames(w, 'Open File', '/')
w.show()
self.EWindow = QtWidgets.QWidget()
self.ui = Ui_Form()
self.ui.setupUi(self.EWindow)
self.EWindow.show()
答案 0 :(得分:0)
使用QPushButton clicked()事件
button = QPushButton('Open', self)
button.clicked.connect(self.on_click)
从QPushButton调用QFileDialog和QMessageBox clicked()事件
def on_click(self):
fileName, _ = QFileDialog.getOpenFileName(self,"Open File", "","All Files (*);;Python Files (*.py)")
if fileName:
print(fileName)
buttonReply = QMessageBox.question(self, 'Message Box', "Do you like PyQt5?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if buttonReply == QMessageBox.Yes:
print('Yes clicked.')
else:
print('No clicked.')