Search code examples
pythonpython-3.xpyqt5qmessagebox

How to display variable in qmessagebox using creator in pyqt5


I am trying to display a variable with some message in qmessagebox using creator. I found similar post here: pyqt: Variable values in QMessageBox output? but it does not work within the creator. Any suggestions how to amend the code below so that it worked?:

purchaseValue = col2SumUp.sum()
msgbox = QMessageBox(QMessageBox.Information, "Value: %s" % purchaseValue, QMessageBox.Ok)

Solution

  • You are missing the title parameter, the following is working for me:

    purchaseValue = 125.2
    msgbox = QMessageBox(QMessageBox.Information, "Title", "Value: %s" % purchaseValue, QMessageBox.Ok)
    msgbox.exec_()
    

    QMessageBox