尝试将WA_QuitOnClose
设置为False。下面的方法对我有用。
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
window.setCentralWidget(QWidget())
window.setAttribute(Qt.WA_QuitOnClose, False)
QShortcut(QKeySequence.Close, window, window.close)
window.show()
sys.exit(app.exec_())