dialogs_2a.py 661 B

12345678910111213141516171819202122
  1. from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel
  2. class CustomDialog(QDialog):
  3. def __init__(self, parent=None):
  4. super().__init__(parent)
  5. self.setWindowTitle("Hello!")
  6. buttons = QDialogButtonBox.Ok | QDialogButtonBox.Cancel
  7. self.buttonBox = QDialogButtonBox(buttons)
  8. self.buttonBox.accepted.connect(self.accepted)
  9. self.buttonBox.rejected.connect(self.rejected)
  10. self.layout = QVBoxLayout()
  11. message = QLabel("Something happened, is that OK?")
  12. self.layout.addWidget(message)
  13. self.layout.addWidget(self.buttonBox)
  14. self.setLayout(self.layout)