源码:
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import *
class infoUI(QMainWindow):
def __init__(self):
super().__init__()
self.info=' '
with open('./main.log', 'r', encoding='utf8') as file:
reads = file.readlines()
print(reads,len(reads))
for i in reads:
self.info+=i
print(self.info)
self.iniUI()
# self.buttonClicked()
def iniUI(self):
self.setWindowTitle("显示信息")
self.resize(1000, 300)
self.text_browser = QTextBrowser(self)#调取文本浏览框显示文本内容
# self.text_browser.setStyleSheet("font-size:18px;color:rgb(0,0,0);background-color:rgb(255,255,255)")#指定RGB字体颜色大小以及背景颜色
# self.text_browser.setStyleSheet("font-size:18px;")#指定字体大小
# self.text_browser.setStyleSheet("color:rgb(210,210,210)")#指定RGB字体颜色
# self.text_browser.setStyleSheet("color:blue")#字体颜色
# self.text_browser.setStyleSheet("background-color:green")#背景颜色
# self.text_browser.setStyleSheet("border-image:url(./qq.png);")#设置背景图
self.text_browser.move(10,10)
self.text_browser.resize(980,280)
self.text_browser.setText(self.info)
def buttonClicked(self):
self.text_browser.setText(self.qle.text())
if __name__ == '__main__':
app = QApplication(sys.argv)
infoUI = infoUI()
infoUI.show()
sys.exit(app.exec_())
打开文本并读取文本所有内容:
self.info=' '
with open('./main.log', 'r', encoding='utf8') as file:
reads = file.readlines()
print(reads,len(reads))
for i in reads:
self.info+=i
print(self.info)
设置QT界面标题和大小:
self.setWindowTitle("显示信息")
self.resize(1000, 300)
调取文本浏览框类,用来显示内容
self.text_browser = QTextBrowser(self)
设置:
# self.text_browser.setStyleSheet("font-size:18px;color:rgb(0,0,0);background-color:rgb(255,255,255)")#指定RGB字体颜色大小以及背景颜色
# self.text_browser.setStyleSheet("font-size:18px;")#指定字体大小
# self.text_browser.setStyleSheet("color:rgb(210,210,210)")#指定RGB字体颜色
# self.text_browser.setStyleSheet("color:blue")#字体颜色
# self.text_browser.setStyleSheet("background-color:green")#背景颜色
# self.text_browser.setStyleSheet("border-image:url(./qq.png);")#设置背景图
显示内容:
self.text_browser.setText(self.info)