pyqt4: AttributeError: 'QPlainTextEdit' ob

2019-03-06 18:47发布

I'm aware that there are similar problems to mine but I tried those solutions and they don't work.

I have text field:

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"))

And i want to add them to the variable string by:

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)`

also I tried:

mailString = self.tMail.plainText()

and I always get an error: AttributeError: 'QPlainTextEdit' object has no attribute '...'

Why?

1条回答
仙女界的扛把子
2楼-- · 2019-03-06 19:04

QPlainTextEdit doesn't have a text() function. try using the toPlainText() function:

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)
查看更多
登录 后发表回答