Home > Enterprise >  TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) [closed]
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) [closed]

Time:10-02

what's wrong with my code? I'm trying to connect my UI file with python. I'm almost sure about everything, but I can't define what the wrong is.

from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.uic import loadUiType

ui = loadUiType('main.ui')


class MainApp(QMainWindow, ui):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUI(self)


def main():
    app = QApplication(sys.argv)
    window = MainApp()
    window.show()
    app.exex_()


if __name__ == '__main__':
    main()

CodePudding user response:

I'm not sure how the 'inheritance' style of UI file loading is supposed to work. However, this should do what you want:

from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.uic import loadUi


class MainApp(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        loadUi('main.ui', self)

def main():
    app = QApplication(sys.argv)
    window = MainApp()
    window.show()
    app.exec_()


if __name__ == '__main__':
    main()
  • Related