凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

PyQt5 dialog组件

2019-09-08 python 1307

1.jpg

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


class MainWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        button = QPushButton("OK", self)

        self.resize(800, 600)
        button.clicked.connect(self.onOKClicked)

    def onOKClicked(self):
        '''
        (1)非模态
        非模态可以和应用程序的其它窗×××互,使用Qt.NonModal进行设置。
        (2)窗口模态
        窗口模态在未处理完成当前对话框时,将阻止和对话框的父窗口进行交互,使用Qt.Modal进行设置。
        (3)应用程序模态
        应用程序模态阻止任何和其它窗口进行交互,使用Qt.ApplicationModal。
        QDialog及其派生类对话框在ESC按键按下时,对话框窗口将会默认调用QDialog.reject方法,关闭对话框。
        '''
        dialog = QDialog()
        # dialog.setWindowModality(Qt.WindowModal)
        dialog.setWindowTitle("Dialog Demo")
        dialog.resize(300, 200)
        dialog.exec_()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWidget()
    window.resize(400, 200)
    window.show()

    sys.exit(app.exec_())


文章评论

0条评论