Python PyQt5: How to show an error message with PyQt5

Ramón Wilhelm picture Ramón Wilhelm · Oct 24, 2016 · Viewed 34.2k times · Source

In normal Python (3.x) we always use showerror() from the tkinter module to display an error message but what should I do in PyQt5 to display exactly the same message type as well?

Answer

NShiell picture NShiell · Jan 8, 2019

Don't forget to call .exec_() to display the error:

from PyQt5.QtWidgets import QMessageBox

msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("Error")
msg.setInformativeText('More information')
msg.setWindowTitle("Error")
msg.exec_()