1. 程式人生 > >關於某個PyQt5系列教程“'QMainWindow' object has no attribute”的錯誤修正

關於某個PyQt5系列教程“'QMainWindow' object has no attribute”的錯誤修正

一直到執行main程式之前之前都沒有什麼錯誤;

但是執行後出錯:

python IDLE報錯:

self.pushButton.clicked.connect(MainWindow.firstPyQt5_button_click)
AttributeError: 'QMainWindow' object has no attribute 'firstPyQt5_button_click'

改正方法:將firstPyQt5.py中的self.pushButton.clicked.connect(MainWindow.firstPyQt5_button_click)

更正為:self.pushButton.clicked.connect(self.firstPyQt5_button_click)

錯誤原因:不能完全說是教程錯誤,感覺也有可能是自己操作問題

根本原因就是因為傳參錯誤,將視窗本身的函式賦值給了父類的MainWindow(python學的不精,個人猜測)

歡迎拍磚