2017-02-28 35 views
0

工作在我的初始化函數,我定義了一個錯誤消息框是這樣的:通過不同的方法我不能讓我的錯誤消息框在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' 

回答

2

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

相關問題