简体   繁体   中英

order (MRO) :Cannot create a consistent method resolution Pyqt5 (inherit python file)

enter image description here

Hi From my previous post, import responsible widget page for tabWidget Python , it was working fine. now i am creating ui files and import in.py file using uic.loadUi (without using pyuic5) as i shown in the pic. while i trying to inherit the page into application.py it is not working. i believe i am doing wrong to apply multiple inheritance. i tried many approaches. but not getting success. can anyone please solve my problem. i even tried converting ui files using pyuic5 and inherit into application.py. but same result. here the google drive link: https://drive.google.com/drive/folders/1UEGw1YR7hxKhH_KK9tX8CiHMgAbEVv5W?usp=sharing

mainWindow.py

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from files.main_interfaces.mainWindow import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow,Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

mainStudent.py

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from files.main_interfaces.student import Ui_Form
class stdMainWindow(QtWidgets.QWidget,Ui_Form):
    def __init__(self, parent=None):
        super(stdMainWindow, self).__init__(parent)
        self.setupUi(self)

        self.pushButton.clicked.connect(self.function1)

    def function1(self):
        print("function called")

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = stdMainWindow()
    w.show()
    sys.exit(app.exec_())

inherit both file mainWindow and mainStudent.py into App.py.

App.py

from PyQt5 import QtCore, QtGui, QtWidgets
from mainAcc import MainWindow
from mainStudent import stdMainWindow

class studentPage(stdMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setupUi(self)


class MainWindow3(MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        # Add tab
        self.studentPage = studentPage()
        self.tabWidget.addTab(self.studentPage, 'Student')

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow3()
    window.show()
    sys.exit(app.exec_())

now if i run App.py, application is running but student page is two times appears and overlapped. error is: QLayout: Attempting to add QLayout "" to studentPage "Form", which already has a layout

now please tell me where i did mistake!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM