ire*_*ses 51
是.您需要覆盖表示应用程序的QWidget的默认关闭行为,以便它不会立即接受该事件.你想要的基本结构是这样的:
def closeEvent(self, event):
quit_msg = "Are you sure you want to exit the program?"
reply = QtGui.QMessageBox.question(self, 'Message',
quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
event.accept()
else:
event.ignore()
Run Code Online (Sandbox Code Playgroud)
las3rjock提到的PyQt 教程对此有一个很好的讨论.另请查看Python.org 的PyQt页面上的链接,特别是官方参考,以了解有关事件以及如何处理事件的更多信息.