3 回答
TA贡献1842条经验 获得超12个赞
您可以选择是否接受该事件。
def closeEvent(self, event):
if self.popup_question():
print("The program was shut down.")
event.accept()
else:
print("not exiting")
event.ignore()
def popup_question(self):
"""Generate a popup that requests if you want to do something or not."""
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Whatever title you want to add.")
msgbox.setIcon(QtWidgets.QMessageBox.Warning)
msgbox.setText("Do you want to quit chit chat?")
botonyes = QtWidgets.QPushButton("Yes")
msgbox.addButton(botonyes, QtWidgets.QMessageBox.YesRole)
botonno = QtWidgets.QPushButton("No")
msgbox.addButton(botonno, QtWidgets.QMessageBox.NoRole)
msgbox.exec_()
if msgbox.clickedButton() == botonno:
return False
else:
return True
添加回答
举报