不正确的函数调用不在PYQT中抛出错误

时间:2017-05-24 17:11:51

标签: python pyqt pyqt5

为什么调用错误的函数self.textBrowser.appendkjsdhsk(" Finished")没有抛出任何错误。它默默地忽略它。

如何确保抛出这些异常? 这是预期的行为吗?

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_XYZ_MainWindow(object):
    def setupUi(self, XYZ_MainWindow):
        XYZ_MainWindow.setObjectName("XYZ_MainWindow")
        XYZ_MainWindow.resize(564, 363)
        self.centralWidget = QtWidgets.QWidget(XYZ_MainWindow)
        self.centralWidget.setObjectName("centralWidget")
        self.textBrowser = QtWidgets.QTextBrowser(self.centralWidget)
        self.textBrowser.setGeometry(QtCore.QRect(20, 80, 521, 201))
        self.textBrowser.setObjectName("textBrowser")
        self.pushButton = QtWidgets.QPushButton(self.centralWidget)
        self.pushButton.setGeometry(QtCore.QRect(340, 40, 80, 22))
        self.pushButton.setObjectName("pushButton")
        XYZ_MainWindow.setCentralWidget(self.centralWidget)
        self.mainToolBar = QtWidgets.QToolBar(XYZ_MainWindow)
        self.mainToolBar.setObjectName("mainToolBar")
        XYZ_MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
        self.retranslateUi(XYZ_MainWindow)
        QtCore.QMetaObject.connectSlotsByName(XYZ_MainWindow)

    def retranslateUi(self, XYZ_MainWindow):
        _translate = QtCore.QCoreApplication.translate
        XYZ_MainWindow.setWindowTitle(_translate("XYZ_MainWindow", "XYZ_MainWindow"))
        self.pushButton.setText(_translate("XYZ_MainWindow", "PushButton"))



import sys
from PyQt5.QtWidgets import QApplication, QMainWindow


class Example_1(QMainWindow, Ui_XYZ_MainWindow):
    def __init__(self, parent=None):
        super(Example_1, self).__init__(parent)
        self.setupUi(self)
        self.pushButton.clicked.connect(self.event_pushButton_clicked)

    def event_pushButton_clicked(self):
        self.textBrowser.append("*****Started*****")
        self.textBrowser.appendkjsdhsk("Finished")

if __name__ == '__main__':
    try: 
        app = QApplication(sys.argv)
        ex1 = Example_1()
        ex1.show()
        sys.exit(app.exec_())
    except:
        print("Done.")

这甚至不会终止GUI或程序。它继续工作,好像那条线不在那里。

多次点击后的结果

0 个答案:

没有答案