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_())
相关推荐
Ivanqhz5 分钟前
Rust parse() 浅析
开发语言·后端·rust
卷无止境11 分钟前
别再被"乱码"吓到了:Python文件操作的门道
后端·python
神仙别闹14 分钟前
基于C++实现(控制台)景区旅游管理系统
开发语言·c++·旅游
STLearner1 小时前
ICML 2026 | LLM×Graph论文总结[2]【Graph4LLM,Graph4Agent,智能体记忆(Memory)
大数据·人工智能·python·深度学习·学习·机器学习·数据挖掘
牛奔8 小时前
Go 如何打印调试深层或嵌套的结构体
开发语言·后端·golang
geovindu9 小时前
go: Iterative Algorithms
开发语言·后端·算法·golang·迭代算法
学逆向的9 小时前
汇编——JCC指令
开发语言·汇编·网络安全
mayaairi10 小时前
JS循环语句深度解析:嵌套for、while与do...while
开发语言·前端·javascript
郭老二10 小时前
【Python】基本语法:装饰器语法糖@
python
kite012110 小时前
Go语言Map深度解析与最佳实践
开发语言·后端·golang