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_())
相关推荐
SomeB1oody4 分钟前
【RustyML入门】7.3. 性能调优与并行
开发语言·后端·机器学习·rust·教程
Java后端的Ai之路5 分钟前
01、Python - 设计模式介绍
java·人工智能·python·设计模式·通用
余额瞒着我当琳12 分钟前
C++STL--list底层实现,迭代器分类,模拟list的迭代器封装、实现
java·开发语言·c++
EW Frontier13 分钟前
【DOA估计】四根天线、一块SDR,神经网络把测向误差压进2度以内【附python代码】
人工智能·python·神经网络·doa估计·aoa估计
小陈的进阶之路13 分钟前
Claude Code辅助测试:API测试与pytest自动化
android·开发语言·kotlin
denggun1234515 分钟前
Python两套原生信号量与swift对比
开发语言·python·swift
kyle~21 分钟前
计算机系统 --- 缓存一致性
开发语言·c++·缓存·计算机系统
qq_161111272 小时前
Jenkins+Python自动化测试持续集成详细教程
自动化测试·python·jenkins·教程·持续集成
爱吃苹果的梨叔5 小时前
训练集群网络中断怎么办?智算机房的 Console 串口排障方案
网络·python·智能路由器·php
李妍.9 小时前
02Numpy基础(上)
开发语言·python