PyQt5-QTextEdit控件使用

QTextEdit是多行文本框控件;即可显示多行文本也可以显示HTML文档;

常用方法:

例如:

 1 #QTextEdit控件使用
 2 
 3 import sys
 4 from  PyQt5.QtWidgets import QPushButton,QApplication,QMainWindow,QLineEdit,QFormLayout,QWidget,QTextEdit,QVBoxLayout
 5 from PyQt5.QtGui import QIntValidator,QDoubleValidator,QRegExpValidator,QFont
 6 from PyQt5.QtCore import  QRegExp,Qt
 7 class QLineEditDemo(QWidget):
 8     def __init__(self,parent=None):
 9         super(QLineEditDemo,self).__init__(parent)
10 
11         self.setWindowTitle("QTextEdit控件使用")
12         self.resize(500,600)
13         self.layout=QVBoxLayout()
14 
15         self.textEdit=QTextEdit()
16         btn_1=QPushButton("显示文本")
17         btn_2=QPushButton("显示HTML")
18         self.layout.addWidget(self.textEdit)
19         self.layout.addWidget(btn_1)
20         self.layout.addWidget(btn_2)
21 
22         self.setLayout(self.layout)
23 
24         btn_1.clicked.connect(self.fn_1)
25         btn_2.clicked.connect(self.fn_2)
26 
27 
28     def fn_1(self):
29         self.textEdit.setPlainText("Hello PyQT5单击按钮")
30 
31     def fn_2(self):
32         self.textEdit.setHtml("<font color='red' size='20'>HELLO!</font>")
33 
34 if __name__=="__main__":
35     app=QApplication(sys.argv)
36     win=QLineEditDemo()
37     win.show()
38     sys.exit(app.exec_())

 

posted @ 2018-12-03 16:33  zyg_100  阅读(10660)  评论(0编辑  收藏  举报