from PyQt5.QtWidgets import *
import sys
class QTextEditDemo(QWidget):
def __init__(self):
super(QTextEditDemo, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("QTextEdit控件演示")
self.resize(300, 280)
self.textEidt = QTextEdit()
self.buttonText = QPushButton('显示文本')
self.buttonHTML = QPushButton('显示HTML')
self.buttonToText = QPushButton('获取文本')
self.buttonToHTML = QPushButton('获取HTML')
self.buttonText.clicked.connect(self.onClick_ButtonText)
self.buttonHTML.clicked.connect(self.onClick_ButtonHTML)
self.buttonToText.clicked.connect(self.onClick_ButtonToText)
self.buttonToHTML.clicked.connect(self.onClick_ButtonToHTML)
layout = QVBoxLayout()
layout.addWidget(self.textEidt)
layout.addWidget(self.buttonText)
layout.addWidget(self.buttonHTML)
layout.addWidget(self.buttonToText)
layout.addWidget(self.buttonToHTML)
self.setLayout(layout)
def onClick_ButtonText(self):
self.textEidt.setPlainText("Hello World, 世界你好吗?")
def onClick_ButtonHTML(self):
self.textEidt.setHtml('<font color="blue" size="5">Hello World</font>')
def onClick_ButtonToText(self):
print(self.textEidt.toPlainText())
def onClick_ButtonToHTML(self):
print(self.textEidt.toHtml())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = QTextEditDemo()
win.show()
sys.exit(app.exec_())
36 QTextEdit控件输入多行文本
最新推荐文章于 2024-07-09 20:59:26 发布