Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复PyQt5代码中的快捷方式?_Python_Qt_Python 3.x_Pyqt_Pyqt5 - Fatal编程技术网

Python 如何修复PyQt5代码中的快捷方式?

Python 如何修复PyQt5代码中的快捷方式?,python,qt,python-3.x,pyqt,pyqt5,Python,Qt,Python 3.x,Pyqt,Pyqt5,我在PyQt5.5.1中使用Ubuntu14.04和Python3.4.3。当我按下Ctrl+Q时,我遇到了一个问题。你能解释一下为什么会发生这种情况以及如何解决这个问题吗。我的代码如下: import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction, QLineEdit, QMessageBox, QLabel from PyQt5.QtGui import QI

我在PyQt5.5.1中使用Ubuntu14.04和Python3.4.3。当我按下Ctrl+Q时,我遇到了一个问题。你能解释一下为什么会发生这种情况以及如何解决这个问题吗。我的代码如下:

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget,  QPushButton, QAction, QLineEdit, QMessageBox, QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot, Qt

class App(QMainWindow):
    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 textbox - pythonspot.com'
        self.left = 10
        self.top = 10
        self.width = 400
        self.height = 140
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        mainMenu = self.menuBar() 
        fileMenu = mainMenu.addMenu('File')
        editMenu = mainMenu.addMenu('Edit')
        viewMenu = mainMenu.addMenu('View')
        searchMenu = mainMenu.addMenu('Search')
        toolsMenu = mainMenu.addMenu('Tools')
        helpMenu = mainMenu.addMenu('Help')
        exitButton = QAction(QIcon('exit24.png'), 'Exit', self)
        exitButton.setShortcut('CTRL+Q')
        exitButton.setStatusTip('Exit application')
        exitButton.triggered.connect(self.close)
        fileMenu.addAction(exitButton)
        self.show()

    @pyqtSlot()
    def on_click(self):
        textboxValue = self.textbox.text()
        QMessageBox.question(self, 'Message - pythonspot.com', "You typed: " + textboxValue, QMessageBox.Ok, QMessageBox.Ok)
        self.textbox.setText("")




if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

我已经试过你的代码,没有遇到任何问题。你在使用哪个操作系统?Arch Linux:P,我按下Ctrl-Q并关闭了窗口。当你点击菜单项时,窗口会关闭吗?快捷方式是否写在项目文本附近?