我正在尝试为学校项目创建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:我得到的错误,(调试适配器意外关闭)
而不是像这样做,试试这个:
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()