Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用PyQt的pythooops_Python_Python 3.x_Oop - Fatal编程技术网

Python 使用PyQt的pythooops

Python 使用PyQt的pythooops,python,python-3.x,oop,Python,Python 3.x,Oop,我正在创建一个多级继承。我怀疑为什么我的构造函数(\uuuu init\uuu)中的基类方法没有得到调用,只有super正在执行 这是我的例子 from PyQt5.QtWidgets import QMainWindow class PSheet(object): def __init__(self): print('PSheet - Start') super(PSheet, self).__init__() print('PSh

我正在创建一个多级继承。我怀疑为什么我的构造函数(
\uuuu init\uuu
)中的基类方法没有得到调用,只有
super
正在执行

这是我的例子

from PyQt5.QtWidgets import QMainWindow

class PSheet(object):

    def __init__(self):

        print('PSheet - Start')
        super(PSheet, self).__init__()
        print('PSheet - End')

        self.some_method()

    def some_method(self):

        print('PSheet - In Some Method')

class config(object):

    def __init__(self):
        print('config - Start')
        super(config, self).__init__()
        print('config - End')

class BaseClassWithQt(QMainWindow, config):

    def __init__(self):
        print('BaseClassWithQt - Start')
        super(BaseClassWithQt, self).__init__()
        print('BaseClassWithQt - End')

class DerivedClassWithQt(BaseClassWithQt, PSheet):

    def __init__(self):
        print('DerivedClassWithQt - Start')
        super(DerivedClassWithQt, self).__init__()
        print('DerivedClassWithQt - End')


print(DerivedClassWithQt.__mro__)
test_with_qt = DerivedClassWithQt()
输出

(<class '__main__.DerivedClassWithQt'>, <class '__main__.BaseClassWithQt'>, <class '__main__.config'>, <class '__main__.PSheet'>, <class 'object'>)
DerivedClassWithQt - Start
BaseClassWithQt - Start
(,)
DerivedClassWithQt-启动
BaseClassWithQt-Start
我不知道我做错了什么,因为我没有得到所有构造器中的所有可用打印

为了澄清,我还打印了两种情况下的mro


我需要更正什么?

这是我运行代码时得到的完整输出(请注意,将来您应该尝试在问题中包含完整输出):

然后,这将为我提供以下输出(无mro):

作为旁注,您可以通过使用参数less
super
来节省一些书写,因为它相当于您所写的内容。例如,对于
BaseWithQt
类和所有其他类,您只需要:

super().__init__()

您的问题看起来很像关于多重继承的其他问题(例如)。Qt与此无关?正如您所建议的参数less super,其工作方式相同。谢谢你的建议。同样,如果没有app=QApplication([]),我不会得到您提到的错误。但是在保留app=QApplication([])之后,我能够从所有的构造器中获得所有的打印结果很好,很高兴它能为您工作
app = QApplication([])

# print(DerivedClassWithQt.__mro__)
test_with_qt = DerivedClassWithQt()
DerivedClassWithQt - Start
BaseClassWithQt - Start
config - Start
PSheet - Start
PSheet - End
PSheet - In Some Method
config - End
BaseClassWithQt - End
DerivedClassWithQt - End
super().__init__()