answerSeeker answerSeeker -4 years ago 195
Python Question

I can't get my error message box to work in pyqt

In my init function, i've defined an error message box like this:

self.error_msg = QtGui.QMessageBox()
self.error_msg.setIcon(QtGui.QMessageBox.critical)
self.error_msg.setWindowTitle("Error")
self.error_msg.setDetailedText("")


on a different method, I try to call the message box like this, by setting the error text:

def detectRoot(self):
euid = os.geteuid()
if euid != 0:
print "need to be root to run this program"
self.logger.error("Not root, program exited")
self.error_msg.setText("You need to be root to run this program")
self.error_msg.exec_()
exit(1)


However, I keep getting message a pyqt/python error:

self.error_msg.setIcon(QtGui.QMessageBox.critical)
TypeError: QMessageBox.setIcon(QMessageBox.Icon): argument 1 has unexpected type 'builtin_function_or_method'

Answer Source

According to the documentation:

QMessageBox::NoIcon: The message box does not have any icon.

QMessageBox::Question: An icon indicating that the message is asking a question. QMessageBox::Information: An icon indicating that the message is nothing out of the ordinary. QMessageBox::Warning: An icon indicating that the message is a warning, but can be dealt with.

QMessageBox::Critical: An icon indicating that the message represents a critical problem.

Change QtGui.QMessageBox.critical to QtGui.QMessageBox.Critical

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download