pyqt5-确认对话框

python 复制代码
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QMessageBox


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Confirmation Dialog Example")

        self.confirm_button = QPushButton("Show Confirmation Dialog", self)
        self.confirm_button.clicked.connect(self.show_confirmation_dialog)

        self.setCentralWidget(self.confirm_button)

    def show_confirmation_dialog(self):
        confirm_dialog = QMessageBox()
        confirm_dialog.setIcon(QMessageBox.Question)
        confirm_dialog.setWindowTitle("Confirmation")
        confirm_dialog.setText("Are you sure you want to proceed?")
        confirm_dialog.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        confirm_dialog.setDefaultButton(QMessageBox.No)

        result = confirm_dialog.exec_()

        if result == QMessageBox.Yes:
            print("User clicked 'Yes'")
        else:
            print("User clicked 'No'")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
相关推荐
数据知道8 分钟前
Go基础:一文掌握Go语言泛型的使用
开发语言·后端·golang·go语言
Brian Xia8 分钟前
# tchMaterial-parser 入门指南
python·ai
啃啃大瓜20 分钟前
常用库函数
开发语言·python
笑口常开xpr25 分钟前
【C++继承】深入浅出C++继承机制
开发语言·数据结构·c++·算法
楼田莉子39 分钟前
python学习:爬虫+项目测试
后端·爬虫·python·学习
你不是我我1 小时前
【Java开发日记】请介绍类加载过程,什么是双亲委派模型?
java·开发语言
总有刁民想爱朕ha1 小时前
Python自动化从入门到实战(17)python flask框架 +Html+Css开发一个实用的在线奖状生成器
python·flask·自动化·在线奖状生成器
teeeeeeemo1 小时前
Webpack 模块联邦(Module Federation)
开发语言·前端·javascript·笔记·webpack·node.js
修炼室1 小时前
如何将Python脚本输出(含错误)全量保存到日志文件?实战指南
开发语言·python
@LetsTGBot搜索引擎机器人2 小时前
用 Python 打造一个 Telegram 二手交易商城机器人
开发语言·python·搜索引擎·机器人·.net·facebook·twitter