How to use ok and cancel button in PyQt6 inside MessageBox
-
msgBox = QtWidgets.QMessageBox() msgBox.setIcon(QtWidgets.QMessageBox.Information) msgBox.setText(msg) msgBox.setWindowTitle("New Window") if dialogFlag == "ok": msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok) elif dialogFlag == "okcancel": msgBox.setStandardButtons( QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel ) response = msgBox.exec() return response
The above code works perfectly fine with PyQt5 but it doesn't work with PyQt6 and throws this error.
msgBox.setIcon(QtWidgets.QMessageBox.Information) AttributeError: type object 'QMessageBox' has no attribute 'Information'
The error is same with Ok and Canel button as well.