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_())
相关推荐
Warson_L13 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅13 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅13 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L13 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅13 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L14 小时前
python的类&继承
python
Warson_L14 小时前
类型标注/type annotation
python
ThreeS16 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵18 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏