PyQt5:类型错误:“错误的基类*部件的”
问题描述:
我创建使用QtDesigner文件,我把它们装入两个单独的窗口显示为以下PyQt5:类型错误:“错误的基类*部件的”
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__()
# Set up the user interface from Designer.
uic.loadUi("interface/UI/main.ui", self)
# Connect up the buttons
self.button_classes.clicked.connect(self.open_classes)
self.w = []
def open_classes(self):
self.w.append(PopupWindow(self))
self.w[-1].show()
class PopupWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__()
# Set up the user interface from Designer.
uic.loadUi("interface/UI/newclass.ui", self)
当我运行在PyCharm代码.UI调试模式下,会出现以下错误,当代码正常运行
TypeError: ('Wrong base class of toplevel widget', (<class 'controllers.GUI.PopupWindow'>, 'QDialog'))
答
您在留言'Wrong base class of toplevel widget', (<class 'controllers.GUI.NewClassWindow'>, 'QDialog'))
有QDialog
,所以我认为它希望你用QDialog
创建第二个窗口,但您使用QMainWindow
然而,在这种情况不会发生class PopupWindowONE(QMainWindow):
当您在console/terminal/cmd.exe/powershell中运行它时是否收到错误消息?添加有问题的完整错误消息。 – furas
@furas当我只是正常运行代码时,没有错误,但是如果我在PyCharm中以调试模式运行代码,我得到一个类型错误,我已经添加到问题 – Ronikos
你有消息''错误的基类('class'controllers.GUI.NewClassWindow'>,'QDialog'))''所以我认为它期望你使用'QDialog'创建第二个窗口,但是你可以在类PopupWindowONE(QMainWindow)中使用'QMainWindow': ' – furas