from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel class CustomDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) self.setWindowTitle("Hello!") buttons = QDialogButtonBox.Ok | QDialogButtonBox.Cancel self.buttonBox = QDialogButtonBox(buttons) self.buttonBox.accepted.connect(self.accepted) self.buttonBox.rejected.connect(self.rejected) self.layout = QVBoxLayout() message = QLabel("Something happened, is that OK?") self.layout.addWidget(message) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout)