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_())
相关推荐
进击的明明20 分钟前
当AI开始“边想边干”:深入聊聊ReAct,以及如何用Python手搓一个简单Agent
python·面试·agent
全栈弄潮儿1 小时前
Python实战第8期:函数
后端·python·编程语言
卷无止境3 小时前
暗流与破局:AI时代的代码安全审查工具全景指南
后端·python
卷无止境5 小时前
一人公司的全栈选型指南:让 AI Agent 写得快,也让生意跑得稳
后端·python
WJ.Polar7 小时前
Java封装、继承、多态
java·开发语言
摇滚侠7 小时前
Java 中如何表示负数,有符号和无符号的区别,补码的计算规则,char byte short int long 的范围
java·开发语言
滴啦嘟啦哒7 小时前
【具身笔记】【π0.5 微调与仿真】五、在MuJoCo中实现可视化仿真
笔记·python·vla·具身
weixin_307779137 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
全栈练习生7 小时前
AI安全与红队测试
python·ai
爱读书的小胖7 小时前
Codewars:Rot13(C)解题分析
c语言·开发语言