【问题标题】:I can't get my error message box to work in pyqt我无法让我的错误消息框在 pyqt 中工作
【发布时间】:2017-02-28 05:39:50
【问题描述】:

在我的 init 函数中,我定义了一个这样的错误消息框:

 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'

【问题讨论】:

    标签: python python-2.7 pyqt pyqt4


    【解决方案1】:

    根据documentation

    QMessageBox::NoIcon:消息框没有任何图标。

    QMessageBox::Question:表示消息正在提问的图标。 QMessageBox::Information:一个图标,表示消息没有什么特别之处。 QMessageBox::Warning:一个图标,表示消息是警告,但可以处理。

    QMessageBox::Critical:表示消息代表严重问题的图标。

    QtGui.QMessageBox.critical 更改为QtGui.QMessageBox.Critical

    【讨论】:

    • 谢谢你 eyllanesc
    猜你喜欢
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2014-01-27
    相关资源
    最近更新 更多