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_())
答案 0 :(得分:-1)
制作:
exitAct.triggered.connect(QtWidgets.qApp.quit)