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_())
相关推荐
cch89185 小时前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神6 小时前
拉链表概念与基本设计
java·开发语言·数据库
chushiyunen6 小时前
python中的@Property和@Setter
java·开发语言·python
禾小西6 小时前
Java中使用正则表达式核心解析
java·python·正则表达式
yoyo_zzm6 小时前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python
小樱花的樱花6 小时前
C++ new和delete用法详解
linux·开发语言·c++
froginwe116 小时前
C 运算符
开发语言
fengfuyao9856 小时前
低数据极限下模型预测控制的非线性动力学的稀疏识别 MATLAB实现
开发语言·matlab
摇滚侠7 小时前
搭建前端开发环境 安装 nodejs 设置淘宝镜像 最简化最标准版本 不使用 NVM NVM 高版本无法安装低版本 nodejs
java·开发语言·node.js