我单击了“平台类型”按钮,但未显示Ui_Form
我尝试了exec_()
,但过程以exit code -1073740791 (0xC0000409)
完成
我想在单击按钮时打开新的QWidget窗口
详细信息:在Python中,当我按下第一个窗口小部件的按钮时,我想再创建一个窗口。我尝试遵循其他内容,但是程序终止并显示错误代码。如果您能让我知道问题出在哪里,我将不胜感激。
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Main_Widget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self._mutex = QtCore.QThread()
self.setupUi(Main_Widget)
def setupUi(self, Main_Widget):
Main_Widget.setObjectName('Main_Widget')
Main_Widget.resize(1272, 640)
self.All_GroupBox = QtWidgets.QGroupBox(Main_Widget)
self.All_GroupBox.setGeometry(QtCore.QRect(20, 10, 1231, 611))
font = QtGui.QFont()
self.All_GroupBox.setFont(font)
self.All_GroupBox.setObjectName('All_GroupBox')
self.verticalLayoutWidget = QtWidgets.QWidget(self.All_GroupBox)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 30, 261, 331))
self.verticalLayoutWidget.setObjectName('verticalLayoutWidget')
self.Button_VerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.Button_VerticalLayout.setContentsMargins(0, 0, 0, 0)
self.Button_VerticalLayout.setObjectName('Button_VerticalLayout')
self.PlatformType_Button = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.PlatformType_Button.setMinimumSize(QtCore.QSize(0, 45))
self.PlatformType_Button.setObjectName('PlatformType_Button')
self.Button_VerticalLayout.addWidget(self.PlatformType_Button)
def PlatformType_Clicked(self):
dialog = Ui_Form(self)
self.dialogs.append(dialog)
dialog.show()
dialog.exec_()
class Ui_Form(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Ui_Form, self).__init__(parent)
def setupUi(self, Form):
Form.setObjectName('Form')
Form.resize(422, 190)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
Main_Widget = QtWidgets.QWidget()
ui = Ui_Main_Widget()
Main_Widget.show()
app.exec_()
答案 0 :(得分:0)
hide()和show()方法,您可以根据需要使用多个对话框,...
def PlatformType_Clicked(self):
dialog.hide()
dialog1.show()
答案 1 :(得分:0)
尝试一下:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Main_Widget(QtWidgets.QWidget):
# def __init__(self):
# super().__init__()
# self._mutex = QtCore.QThread()
# self.setupUi(Main_Widget)
def setupUi(self, Main_Widget):
Main_Widget.setObjectName('Main_Widget')
Main_Widget.resize(1272, 640)
self.All_GroupBox = QtWidgets.QGroupBox(Main_Widget)
self.All_GroupBox.setGeometry(QtCore.QRect(20, 10, 1231, 611))
font = QtGui.QFont()
self.All_GroupBox.setFont(font)
self.All_GroupBox.setObjectName('All_GroupBox')
self.verticalLayoutWidget = QtWidgets.QWidget(self.All_GroupBox)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 30, 261, 331))
self.verticalLayoutWidget.setObjectName('verticalLayoutWidget')
self.Button_VerticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.Button_VerticalLayout.setContentsMargins(0, 0, 0, 0)
self.Button_VerticalLayout.setObjectName('Button_VerticalLayout')
self.PlatformType_Button = QtWidgets.QPushButton("PlatformType_Button", self.verticalLayoutWidget)
self.PlatformType_Button.setMinimumSize(QtCore.QSize(0, 45))
self.PlatformType_Button.setObjectName('PlatformType_Button')
# +++
self.PlatformType_Button.clicked.connect(Main_Widget.PlatformType_Clicked) # +++
self.Button_VerticalLayout.addWidget(self.PlatformType_Button)
# def PlatformType_Clicked(self):
# dialog = Ui_Form(self)
# self.dialogs.append(dialog)
# dialog.show()
# dialog.exec_()
class Ui_Form(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Ui_Form, self).__init__(parent)
def setupUi(self, Form):
Form.setObjectName('Form')
Form.resize(422, 190)
class MyWindow(QtWidgets.QWidget): # +++
def __init__(self):
super().__init__()
self.ui = Ui_Main_Widget()
self.ui.setupUi(self)
# +++
def PlatformType_Clicked(self):
self.dialog = Ui_Form() # --- self
# self.dialogs.append(dialog)
self.dialog.show()
# self.dialog.exec_()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = MyWindow()
w.show()
sys.exit(app.exec_())