dialogs_5.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import sys
  2. from PyQt5.QtWidgets import QMainWindow, QPushButton, QMessageBox, QApplication
  3. class MainWindow(QMainWindow):
  4. def __init__(self):
  5. super().__init__()
  6. self.setWindowTitle('My App')
  7. button = QPushButton('Press me for a dialog!')
  8. button.setCheckable(True)
  9. button.clicked.connect(self.button_clicked)
  10. self.setCentralWidget(button)
  11. def button_clicked(self, is_checked):
  12. # button = QMessageBox.question(self, "Question dialog", "The longer message")
  13. button = QMessageBox.critical(
  14. self,
  15. 'Oh dear!',
  16. 'Somthing went very wrong',
  17. buttons=QMessageBox.Discard
  18. | QMessageBox.NoToAll
  19. | QMessageBox.Ignore,
  20. defaultButton=QMessageBox.Discard,
  21. )
  22. if button == QMessageBox.Discard:
  23. print("Discard!")
  24. elif button == QMessageBox.NoToAll:
  25. print("No to all!")
  26. else:
  27. print("Ignore!")
  28. app = QApplication(sys.argv)
  29. window = MainWindow()
  30. window.show()
  31. sys.exit(app.exec_())