辽宁高速公路建设管理局网站,织梦文章类网站模板,wordpress分类添加html,孝感个人网站建设PyQt ------ QTextEditor 引言正文示例1------进阶示例 引言
这里给大家介绍一下 PyQt6 中的 QTextEditor 组件用法。
正文
QTextEditor 可以进行多行字符串输出的组件。
想要获取 QTextEditor 组件中当前存放的字符串#xff0c;需要使用#xff1a;
QTextEditor.toPla… PyQt ------ QTextEditor 引言正文示例1------进阶示例 引言
这里给大家介绍一下 PyQt6 中的 QTextEditor 组件用法。
正文
QTextEditor 可以进行多行字符串输出的组件。
想要获取 QTextEditor 组件中当前存放的字符串需要使用
QTextEditor.toPlainText()想要对 QTextEditor 组件中的字符串进行更新需要使用
QTextEditor.setText()示例1------进阶示例
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButtonclass TextEditorDemo(QWidget):def __init__(self, parentNone):super(TextEditorDemo, self).__init__(parent)self.setWindowTitle(QTextEditor Example)self.text_editor QTextEdit()self.text_editor.setText(JiJi is smart. \nShe is also beautiful.\nShe is 26 years old)self.text_editor.setFixedSize(400, 200)button QPushButton()button.setText(Change QTextEdit message)button.clicked.connect(self.button_clicked)layout QVBoxLayout(self)layout.addWidget(self.text_editor)layout.addWidget(button)def button_clicked(self):self.text_editor.setText(Do you want to be her friend?\nDo you want to go outside with her?)if __name__ __main__:app QApplication(sys.argv)win TextEditorDemo()win.show()sys.exit(app.exec())运行后的界面如下 点击后得到的界面如下 如果大家觉得有用就请点个赞吧~