pyqt5|pyqt5(12)-模式和非模式对话框-exec-show()

pyqt5|pyqt5(12)-模式和非模式对话框-exec-show()
文章图片


exec_模式对话框,就是在弹出窗口的时候,整个程序就被锁定了,处于等待状态,直到对话框被关闭
show()非模式对话框,在调用弹出窗口之后,调用即刻返回,继续下面的操作。
上代码:
mainWind

class CUi_maindlgs(QtWidgets.QMainWindow,Ui_MainWindow): def __init__(self): super(CUi_maindlgs, self).__init__() self.setupUi(self) self.dlg1 = CUi_dlg1(self)#1.作为成员变量 self.pushButton.clicked.connect(self.onclick1) self.pushButton_2.clicked.connect(self.onclick2) def onclick1(self): self.dlg1.show()#Mainwindow 用show() def onclick2(self): dlg2 = CUi_dlg2(self)#2.直接成为局部变Qdialog用exec() dlg2.exec()

dlg1:QtWidgets.QMainWindow 用show()
class CUi_dlg1(QtWidgets.QMainWindow,Ui_Dialog): def __init__(self,parent=None): super(CUi_dlg1, self).__init__(parent) self.setupUi(self)if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = CUi_dlg1() MainWindow.show() sys.exit(app.exec_())

dlg2QDialog用exec()
class CUi_dlg2(QDialog,Ui_Dialog): def __init__(self,parent=None): super(CUi_dlg2, self).__init__(parent) self.setupUi(self)if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = CUi_dlg2() MainWindow.show() sys.exit(app.exec_())

【pyqt5|pyqt5(12)-模式和非模式对话框-exec-show()】代码:pyqt5-模式和非模式对话框mainwindow和QDialog版-Python文档类资源-CSDN下载

    推荐阅读