在寫繼承子類的時候出現了TypeError: super() takes at least 1 argument (0 given)的error;
源代碼(python3中完美可運行):
class Example(QWidget): def __init__(self): super().__init__() self.initUI() #界面繪制交給InitUi方法
原因是super().__init__()函數在python3中支持,是正確的,但是放到python2中會出現問題;
如果在python2想要繼承父類的構造方法,則需要給super參數中傳入參數:super(Example,self).__init__();
python2中需這樣寫:
class Example(QWidget): def __init__(self): super(Example,self).__init__() self.initUI() #界面繪制交給InitUi方法