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_())
文章来源:https://www.toymoban.com/news/detail-653458.html
文章来源地址https://www.toymoban.com/news/detail-653458.html
到了这里,关于pyqt5-确认对话框的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!