0
我儘量讓鍵盤快捷鍵臨界彈出消息後,退出應用程序。我想讓用戶按下鍵盤快捷鍵,然後提示重要消息,點擊是後它將退出程序。我一直在嘗試一段時間,並無法讓它工作。這裏是我有的Python PyQt4的鍵盤快捷鍵
這裏是我的代碼
import sys
import webbrowser
import random
import time
import os
import subprocess
from PyQt4.QtCore import QSize, QTimer
from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, QWidget, QIcon, QLabel, QPainter, QPixmap, QMessageBox, \
QAction, QKeySequence
def CloseSC(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("This is a message box")
msg.setInformativeText("This is additional information")
msg.setWindowTitle("MessageBox demo")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
class MainWindow(QMainWindow,):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setGeometry(50, 50, 400, 450)
self.setFixedSize(400, 450)
self.startUIWindow()
self.actionExit = QAction(('E&xit'), self)
self.actionExit.setShortcut(QKeySequence("Ctrl+Q"))
self.actionExit.triggered.connect(CloseSC)