PyQt: 练习 QDialogPyQt: 练习 QDialogPyQt: 练习 QDialogPyQt: 练习 QDialog
  • 首页
  • 博客
  • 文件
  • 书签
  • 分析
  • 登录
Search
Generic filters

PyQt: 练习 QDialog

Published by admin at 2022年4月15日
Categories
  • Practice
Tags
import sys
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()
        self.dialogue_func()

    def setup_ui(self):
        self.setWindowTitle("Qt桌面应用程序")
        self.resize(300, 300)
        self.label = QLabel(self)
        self.label.resize(200, 30)
        self.label.setStyleSheet("background-color:cyan")

        self.push_button = QPushButton(self)
        self.push_button.setText("按钮")
        self.push_button.move(30, 100)

        def push_button_clicked():
            # self.dialogue.open()
            # self.dialogue.exec()
            self.dialogue.show()

        self.push_button.clicked.connect(push_button_clicked)

    def dialogue_func(self):
        self.dialogue = QDialog(self)
        self.dialogue.setWindowTitle("对话框")
        self.dialogue.resize(400, 200)
        # self.dialogue.setModal(True)
        self.dialogue.setWindowModality(Qt.WindowModal)
        self.dialogue.setSizeGripEnabled(True)

        self.dialogue_accept_button = QPushButton(self.dialogue)
        self.dialogue_accept_button.setText("确定")
        self.dialogue_accept_button.move(50, 50)

        self.dialogue_reject_button = QPushButton(self.dialogue)
        self.dialogue_reject_button.setText("取消")
        self.dialogue_reject_button.move(150, 50)

        self.dialogue_done_button = QPushButton(self.dialogue)
        self.dialogue_done_button.setText("完成")
        self.dialogue_done_button.move(250, 50)

        self.dialogue_accept_button.clicked.connect(lambda: self.dialogue.accept())
        self.dialogue_reject_button.clicked.connect(lambda: self.dialogue.reject())
        self.dialogue_done_button.clicked.connect(lambda: self.dialogue.done(9))

        self.dialogue.accepted.connect(lambda: self.label.setText("接受 " + "结果:" + str(self.dialogue.result())))
        self.dialogue.rejected.connect(lambda: self.label.setText("拒绝 " + "结果:" + str(self.dialogue.result())))
        self.dialogue.finished.connect(lambda: self.label.setText("完成 " + "结果:" + str(self.dialogue.result())))


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

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Categories

  • 猫
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2022 Alaica Blog support@alaica.com