PyQt5对话框使用

#QMessageBox
#QColorDialog
#QFileDialog
#QFontDialog
#QInputDialog

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class QDialogDemo(QMainWindow):
    def __init__(self):
        super(QDialogDemo,self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("QDialog案例")
        self.resize(300,200)

        self.button = QPushButton('弹出对话框',self)
        self.button.move(50,50)
        self.button.clicked.connect(self.showDialog)

    def showDialog(self):
        dialog = QDialog()
        button = QPushButton('确定',dialog)
        button.clicked.connect(dialog.close)

        button.move(50,50)
        dialog.setWindowTitle('对话框')
        #模态显示
        dialog.setWindowModality(Qt.ApplicationModal)
        #显示
        dialog.exec()

if __name__ == '__main__':
    app =QApplication(sys.argv)

    main = QDialogDemo()
    main.show()
    app.exit(app.exec_())

PyQt5对话框使用_第1张图片

你可能感兴趣的:(PyGt5,GUI)