PyQt5: Closing Window Command does not work

时间:2017-08-13 13:43:07

标签: python pyqt5

I have a problem and since I haven't found a similar question to my problem I am asking a question.

I am trying to close a window but the command for it doesn't work.

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Main(QMainWindow):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        exitAct = QAction(QIcon('exit.ico'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit) #This is the command I am refering to

        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAct)

        menu = QMenu()
        menuItem1 = menu.addAction('File Explorer')
        menuItem2 = menu.addAction('WritePad')
        menuItem3 = menu.addAction('Settings')

        startButton=QPushButton("Start", self)
        startButton.setGeometry(0, 35, 100, 50)
        startButton.setMenu(menu)

        self.showFullScreen()

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Main()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:-1)

制作:

exitAct.triggered.connect(QtWidgets.qApp.quit)
相关问题