看看下面的MWE.
import sys
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.button = QPushButton('Bham!')
self.setCentralWidget(self.button)
self.button.clicked.connect(self.btnClicked)
def btnClicked(self):
print(sys.excepthook)
raise Exception
#import traceback
#sys.excepthook = traceback.print_exception
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
app.exec_()
我有很多问题.我不知道他们是否都是相关的(我猜是这样),所以请原谅我,如果不是.
>当我从终端运行上面的代码时,一切都很好.该程序运行,如果我点击按钮它会打印回溯并死掉.如果我在IDE中运行它(我测试了Spyder和PyCharm),则不会显示回溯.知道为什么吗?在SO,here和here上的其他帖子中也提出了同样的问题.请不要将此标记为其中任何一个的副本;请继续阅读.
>通过添加注