AttributeError: 'QTextEdit' object has no attribute 'text'
时间: 2023-09-20 16:06:22
浏览: 185
This error occurs when you try to access the 'text' attribute of a QTextEdit object, which does not exist. QTextEdit is a wid[get](https://geek.csdn.net/educolumn/31aebce56f4ecc5451aac3a194ff6259?spm=1055.2569.3001.10083) used for displaying and editing plain or formatted text, and it has a 'toPlainText()' method that can be used to retrieve the contents of the wid[get](https://geek.csdn.net/educolumn/31aebce56f4ecc5451aac3a194ff6259?spm=1055.2569.3001.10083) as a [string](https://geek.csdn.net/edu/8802d631b97a4a6af1f4d0bbf8527465?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083).
Instead of using 'text', you can use 'toPlainText()' to [get](https://geek.csdn.net/educolumn/31aebce56f4ecc5451aac3a194ff6259?spm=1055.2569.3001.10083) the contents of the QTextEdit object. For example:
my_text_edit = QTextEdit()
text = my_text_edit.toPlainText()
This will retrieve the text in the QTextEdit object and store it in the 'text' v[aria](https://geek.csdn.net/educolumn/463d440d0a4c351bc15e5ce55f37f0bb?spm=1055.2569.3001.10083)ble.
相关问题
AttributeError: 'QTextEdit' object has no attribute 'TextCursor'
AttributeError: 'QTextEdit' object has no attribute 'TextCursor' 是一个 Python 错误,它通常出现在使用 PyQt5 开发 GUI 应用程序时。这个错误的原因可能是因为代码中使用了错误的属性名,例如 "T
AttributeError: 'QTextEdit' object has no attribute 'returnPressed'
相关推荐
















