【发布时间】:2022-01-08 11:22:21
【问题描述】:
我使用 QtDesigner 创建了 .ui 文件,并将它们加载到两个单独的窗口中,如下所示
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中调试模式运行代码时,出现如下错误,但代码正常运行时不会出现这种情况
TypeError: ('Wrong base class of toplevel widget', (<class 'controllers.GUI.PopupWindow'>, 'QDialog'))
【问题讨论】:
-
在控制台/终端/cmd.exe/powershell 中运行时是否收到错误消息?添加有问题的完整错误消息。
-
@furas 当我只是正常运行代码时,没有错误,但是如果我在 PyCharm 中以调试模式运行代码,我会收到我添加到问题中的类型错误
-
你有消息
'Wrong base class of toplevel widget', (<class 'controllers.GUI.NewClassWindow'>, 'QDialog'))所以我认为它希望你使用QDialog创建第二个窗口,但你在class PopupWindowONE(QMainWindow):中使用QMainWindow -
@furas 非常感谢您的帮助,将
class PopupWindowONE(QMainWindow)更改为class PopupWindowONE(QDialog)解决了问题。我相信这是因为我在 QtDesigner 中选择了“带按钮的对话框”模板。如果您想回答,我已更改问题以正确反映问题
标签: python python-3.x pyqt pyqt5