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_())
相关推荐
stay night484 分钟前
DAY31
数据库·python
幽蓝计划6 分钟前
鸿蒙仓颉开发语言实战教程:实现商城应用详情页
开发语言·华为·harmonyos
Pocker_Spades_A8 分钟前
Python刷题:神奇的函数
开发语言·python
老大白菜12 分钟前
双均线量化交易策略指南
python·fastapi
Your易元1 小时前
设计模式-备忘录模式
java·开发语言·spring·设计模式
零叹1 小时前
篇章二 需求分析(一)
java·开发语言·mq·生产者消费者模型·brokerserver
覆东流2 小时前
python安装与使用
开发语言·python
玉笥寻珍3 小时前
数字政务安全实战:等保2.0框架下OA系统防护全解析
python·安全·政务
..过云雨6 小时前
01. Qt介绍及Qt开发环境搭建(2025.05最新官网下载方式)
开发语言·qt
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ7 小时前
crud方法命名示例
java·开发语言