我不能让我的错误消息框在PyQt的

问题描述:

工作在我的初始化函数,我定义了一个错误消息框是这样的:通过不同的方法我不能让我的错误消息框在PyQt的

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

,我尝试调用消息盒这样,通过设置错误文本:

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) 

不过,我不断收到消息的PyQt/Python的错误:

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

Accordin克至该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.

变化QtGui.QMessageBox.criticalQtGui.QMessageBox.Critical

+0

谢谢eyllanesc – answerSeeker

+0

如果我的回答可以帮助你,将其标记为正确的。 – eyllanesc