I am having an error when I exit my GUI:
Error: "python.exe has stopped working"
This happens when I exit using the topmenu and toolbar exit option. And it also happens when I close the program on the "X" on the top right.
However when I comment the line:
self.mainToolBar.addAction(exitAction)
The "X" on the top right wont give this error.
For the exit option on the toolbar and top menu I am using this:
exitAction.triggered.connect(qApp.quit)
Follow the code:
class Example(QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.topmenu()
self.toolbar()
self.resize(800, 600)
self.setWindowTitle('Example')
self.setWindowIcon(QtGui.QIcon('test.gif'))
self.show()
def topmenu(self):
#Buttons
exitAction = QAction(QtGui.QIcon('plus.gif'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
#Create MenuBar
menubar = self.menuBar()
#Add options
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
def toolbar(self):
exitAction = QAction(QtGui.QIcon('plus.gif'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setToolTip("Exit")
exitAction.triggered.connect(qApp.quit)
self.mainToolBar = QToolBar(self)
self.mainToolBar.setObjectName("mainToolBar")
self.addToolBar(Qt.LeftToolBarArea, self.mainToolBar)
# Line is giving the stop problem
self.mainToolBar.addAction(exitAction)
def main():
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
How do I fix this?