注册 登录
编程论坛 Python论坛

【求助】运行后退出的问题

xiangyue0510 发布于 2018-06-13 14:49, 2015 次点击
其实就是做了两个菜单和工具栏按钮。其中一个是关于,按照设想是点击后弹出关于的对话框。
但是运行的时候,直接报错退出了。请教各位大神
Process finished with exit code -1073740791 (0xC0000409)

程序代码:

import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon


class Example(QMainWindow):

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

        self.initUI()


    def initUI(self):
        self.statusBar().showMessage('Ready')  # 设置状态栏

        # 设置一个退出的动作按钮
        exitAction = QAction(QIcon('web.png'), '&Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(qApp.quit)

        aboutAction = QAction(QIcon('web.png'), '&About', self)
        aboutAction.setStatusTip('About application')
        aboutAction.triggered.connect(self.onAboutTriggered)

        #创建一个菜单栏
        menubar = self.menuBar()
        #添加菜单
        fileMenu = menubar.addMenu('&File')
        #添加事件(菜单按钮),与前面定义好的动作按钮对应
        fileMenu.addAction(exitAction)

        aboutMenu= menubar.addMenu('&About')
        aboutMenu.addAction(aboutAction)

        # 创建工作栏,并与前面定义好的动作按钮对应
        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAction)

        self.toolbar = self.addToolBar('Help')
        self.toolbar.addAction(aboutAction)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Menubar')
        self.show()

    def onAboutTriggered(self):
        QMessageBox.about(self, "About", "About this application")



if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
1 回复
#2
xiangyue05102018-06-14 14:33
我自己在做另一个例子的时候发现原因了。
加一句from PyQt5.QtWidgets import QMessageBox 就可以了
不知道为何run的时候不会报警,而是在点击这个按钮的时候直接退出。
1