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_())
相关推荐
带土14 分钟前
8. C++ explicit 关键字
开发语言·c++
人道领域7 分钟前
【零基础学java】(TCP协议)
java·开发语言·tcp/ip
小二·8 分钟前
Python Web 开发进阶实战:微前端架构初探 —— 基于 Webpack Module Federation 的 Vue 微应用体系
前端·python·架构
rgeshfgreh9 分钟前
回溯算法精解:排列、子集与组合
python·算法·深度优先
内存不泄露11 分钟前
人脸识别考勤系统
ide·vue.js·python
Star Learning Python19 分钟前
30道经典java面试题
java·开发语言
wearegogog12320 分钟前
NOMA下行链路用户与信道功率分配优化MATLAB实现
开发语言·matlab
jiayong2323 分钟前
Word图文混排实战技巧
开发语言·c#·word
hqwest23 分钟前
码上通QT实战27--系统设置02-加载用户列表
开发语言·qt·sqlite·qtablewidget