PyQt5之QDialog(十二)

import sys
from PyQt5.QtWidgets import QWidget,QApplication,QDialog,QPushButton
from PyQt5.QtCore import Qt

#QDialog类的子类主要有QMessageBox,QFileDialog,QColorDialog,QFontDialog,QInputDialog
class dialogDemo(QWidget):
    def __init__(self):
        super(dialogDemo, self).__init__()

        self.button = QPushButton(self)
        self.button.setText("弹出对话框")
        self.button.move(100,100)
        self.button.clicked.connect(self.openNewDialog)

        self.resize(300,300)
        self.setWindowTitle("dialogDemo")

    def openNewDialog(self):
        dialog = QDialog()
        dialog.setWindowTitle("Dialog Window")
        dialog.setWindowModality(Qt.ApplicationModal) #必须关闭对话窗口 后 才能 关闭主窗口
        #dialog.setWindowModality(Qt.WindowModal) #关闭主窗口后 不影响对话窗口
        #dialog.setWindowModality(Qt.NonModal)  #必须关闭对话窗口 后 才能 关闭主窗口
        dialog.exec_()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dialog = dialogDemo()
    dialog.show()
    sys.exit(app.exec_())

参考: PyQt5基本控件详解之QDialog(十二)_jia666666的博客-CSDN博客_pyqt5 qdialog

你可能感兴趣的:(PyQt,qt,开发语言,ui)