pyqt4:AttributeError:'QPlainTextEdit'对象没有属性'text'

时间:2018-06-12 18:47:29

标签: python error-handling pyqt4

我知道我遇到了类似的问题,但是我尝试了这些解决方案但它们无法正常工作。

我有文字字段:

self.tMail = QtGui.QPlainTextEdit(self.centralwidget)
self.tMail.setGeometry(QtCore.QRect(50, 270, 451, 75))
self.tMail.setAccessibleName(_fromUtf8(""))
self.tMail.setInputMethodHints(QtCore.Qt.ImhNone)
self.tMail.setPlainText(_fromUtf8(""))
self.tMail.setOverwriteMode(False)
self.tMail.setObjectName(_fromUtf8("tMail"))

我想通过以下方法将它们添加到变量字符串中:

def handleButton(self):
    timeString = self.tCzas.text()
    mailString = self.tMail.text()
    IDString = self.tID.text()
    teamString = self.tTeam.text()
    print(timeString)
    print(mailString)
    print(IDString)
    print(teamString)`

我也尝试过:

mailString = self.tMail.plainText()

我总是收到错误: AttributeError: 'QPlainTextEdit' object has no attribute '...'

为什么?

1 个答案:

答案 0 :(得分:0)

QPlainTextEdit没有text()功能。尝试使用toPlainText()函数:

def handleButton(self):
    timeString = self.tCzas.toPlainText()
    mailString = self.tMail.toPlainText()
    IDString = self.tID.toPlainText()
    teamString = self.tTeam.toPlainText()
    print(timeString)
    print(mailString)
    print(IDString)
    print(teamString)