pyqt5 一个按钮 点开一个对话框

pyqt5 一个按钮 点开一个对话框

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):
        dialog = QDialog()
        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_())

在这里插入图片描述
在这里插入图片描述

发布了824 篇原创文章 · 获赞 313 · 访问量 105万+

猜你喜欢

转载自blog.csdn.net/wowocpp/article/details/105200140