PyQt5无法打开另一个窗口(调试适配器意外关闭)

问题描述 投票:0回答:1

我正在尝试为学校项目创建GUI,所以我正在使用pyqt5,但是我是新手,每次单击时,我需要打开一些新窗口(已经在Qt Creator中创建了)。在希望打开另一个窗口的那些按钮之一上,程序意外关闭。我该怎么办才能修复它,或者应该在哪里查看?

# defines what the button does 
def precios_ventana(self):
    self.window=QtWidgets.QMainWindow()
    self.ui= Ui_PreciosWindow()
    self.ui.setupUi(self,window)
    self.window.show()


# opens the window when i click the button
    self.btnprecios.setObjectName("btnprecios")
    self.btnprecios.clicked.connect(self.precios_ventana)

1:主窗口正在工作,然后单击标记的按钮之一

“”

2:我得到的错误,(调试适配器意外关闭)

“”

python python-3.x pyqt pyqt5 python-3.7
1个回答
0
投票

而不是像这样做,试试这个:

class PreciosVentana(QtGui.QMainWindow):
    def __init__(self, parent):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_PreciosWindow()
        self.ui.setupUi(self)

# your class goes here
class TheMainWindow(QtGui.QMainWindow):

    def precios_ventana(self):
        ventana = PreciosVentana(self)
        ventana.show()
© www.soinside.com 2019 - 2024. All rights reserved.