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_())
相关推荐
学IT的周星星4 分钟前
java常见面试题
java·开发语言
Together_CZ4 分钟前
DarkIR: Robust Low-Light Image Restoration——鲁棒的低光照图像复原
python·image·robust·darkir·鲁棒的低光照图像复原·low-light·restoration
wjs202414 分钟前
XPath 运算符
开发语言
Mr.朱鹏17 分钟前
大模型入门学习路径(Java开发者版)上
java·开发语言·spring boot·spring·大模型·llm·transformer
拾贰_C18 分钟前
【python | pytorch | scipy】scipy scikit-learn库相互依赖?
pytorch·python·scipy
黎雁·泠崖19 分钟前
C 语言指针进阶教程:const 修饰、野指针规避与传址调用
c语言·开发语言
lsx20240624 分钟前
ASP TextStream
开发语言
BoBoZz1925 分钟前
PolyDataContourToImageData 3D集合图像转换成等效3D二值图像
python·vtk·图形渲染·图形处理
cike_y27 分钟前
JSP标签&JSTL标签&EL表达式
java·开发语言·jsp
2401_8414956429 分钟前
【自然语言处理】关系性形容词的特征
人工智能·python·自然语言处理·自动识别·特征验证·关系性形容词·语言学规则和计算