[英]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: 在我的init函数中,我定义了一个错误消息框,如下所示:
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: 但是,我不断收到消息pyqt / python错误:
self.error_msg.setIcon(QtGui.QMessageBox.critical)
TypeError: QMessageBox.setIcon(QMessageBox.Icon): argument 1 has unexpected type 'builtin_function_or_method'
According to the documentation : 根据文档 :
QMessageBox::NoIcon : The message box does not have any icon. QMessageBox :: NoIcon :消息框没有任何图标。
QMessageBox::Question : An icon indicating that the message is asking a question. QMessageBox :: Question :一个图标,指示消息正在询问问题。 QMessageBox::Information : An icon indicating that the message is nothing out of the ordinary. QMessageBox :: Information :一个图标,指示消息没有异常。 QMessageBox::Warning : An icon indicating that the message is a warning, but can be dealt with. QMessageBox :: Warning :一个图标,指示消息是警告,但可以处理。
QMessageBox::Critical : An icon indicating that the message represents a critical problem. QMessageBox :: Critical :一个图标,指示消息表示严重问题。
Change QtGui.QMessageBox.critical
to QtGui.QMessageBox.Critical
更改QtGui.QMessageBox.critical
到QtGui.QMessageBox.Critical
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.