Python 在不关闭主程序的情况下关闭PyQt对话框

Python 在不关闭主程序的情况下关闭PyQt对话框,python,combobox,pyqt,dialog,Python,Combobox,Pyqt,Dialog,在使用这些输入提醒python程序之前,我试图使用Qt设计器中创建的PyQt对话框获取一些用户输入(复杂度等级、材质类型和机器类型)。对话框中显示的选项将从字典中读取。我的问题是,无论我尝试了什么,通过按下submit按钮关闭对话框都会停止程序的其余部分运行,无论我是将对话框保留在主py程序中,还是将其作为单独文件中的函数运行。我很确定它与sys.exit(app.exec_389;())行有关,我还尝试使用.close和.reject关闭对话框,结果相同。另外,我知道这个程序不是很好,我正在销

在使用这些输入提醒python程序之前,我试图使用Qt设计器中创建的PyQt对话框获取一些用户输入(复杂度等级、材质类型和机器类型)。对话框中显示的选项将从字典中读取。我的问题是,无论我尝试了什么,通过按下submit按钮关闭对话框都会停止程序的其余部分运行,无论我是将对话框保留在主py程序中,还是将其作为单独文件中的函数运行。我很确定它与
sys.exit(app.exec_389;())
行有关,我还尝试使用.close和.reject关闭对话框,结果相同。另外,我知道这个程序不是很好,我正在销毁函数中传递的变量,但是如果你对如何让我的程序的其余部分与对话框对话有任何建议,我将不胜感激,我已经在这个问题上用尽了谷歌的其余部分,非常感谢

import os
import numpy as np

def get_part_info():
    material_ops =[]
    complex_ops = [1,2,3]
    machine_ops = []
    
#---Dictionary containing material options and machine options is read out here, this part works fine ----
    
    mat_choice = 'empty'
    comp_choice = 'empty'
    mach_choice = 'empty'
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(227, 217)
            self.verticalLayout_3 = QtWidgets.QVBoxLayout(Dialog)
            self.verticalLayout_3.setObjectName("verticalLayout_3")
            self.verticalLayout = QtWidgets.QVBoxLayout()
            self.verticalLayout.setObjectName("verticalLayout")
            self.Material = QtWidgets.QComboBox(Dialog)
            self.Material.setObjectName("Material")
            self.verticalLayout.addWidget(self.Material)
            self.Complexity = QtWidgets.QComboBox(Dialog)
            self.Complexity.setObjectName("Complexity")
            self.verticalLayout.addWidget(self.Complexity)
            self.Machine = QtWidgets.QComboBox(Dialog)
            self.Machine.setObjectName("Machine")
            self.verticalLayout.addWidget(self.Machine)
            self.textEdit = QtWidgets.QTextEdit(Dialog)
            self.textEdit.setObjectName("textEdit")
            self.verticalLayout.addWidget(self.textEdit)
            self.verticalLayout_3.addLayout(self.verticalLayout)
            self.Submit = QtWidgets.QPushButton(Dialog)
            self.Submit.setMaximumSize(QtCore.QSize(100, 16777215))
            self.Submit.setObjectName("Submit")
            self.verticalLayout_3.addWidget(self.Submit, 0, QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)

#------Read out from the dictionary is added to the drop down menus here-----

            for i in list(material_ops):
                self.Material.addItem(i)
            for i in list(complex_ops):
                self.Complexity.addItem(str(i))
            for i in list(machine_ops):
                self.Machine.addItem(i)
    
            self.Submit.pressed.connect(self.save)
            self.retranslateUi(Dialog)
            self.Submit.pressed.connect(Dialog.reject)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            _translate = QtCore.QCoreApplication.translate
            Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
            self.Submit.setText(_translate("Dialog", "Submit"))
    
        def save(self):
            global mat_choice, comp_choice, mach_choice
            mat_choice = (self.Material.currentText())
            comp_choice = (self.Complexity.currentText())
            mach_choice = (self.Machine.currentText())
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Dialog = QtWidgets.QDialog()
        ui = Ui_Dialog()
        ui.setupUi(Dialog)
        Dialog.show() 
        sys.exit(app.exec_())
        return mat_choice, comp_choice, mach_choice, matdict
        
get_part_info()

print('Rest of programme is working') # programme never gets this far

#---The rest of the programme that uses these user chosen options is here and never runs due to the dialog closing stopping the whole programme ------

您不能先关闭此窗口,然后再打开另一个窗口。
你可以在它不再适用后隐藏它。

我通过删除
sys.exit(app.exec())
行解决了这个问题,并使用了
app.exec()
,它成功地运行了输入对话框,然后使用选择的值运行了程序的其余部分。我不能假装知道为什么它现在能工作,但如果有人遇到类似的问题,它会工作。

程序的其余部分也使用PyQt吗?@musicamante否我只使用PyQt获取用户输入