We won't explain the code one by one , The code is as follows :
from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import
QFileDialog,QColorDialog,QApplication,QTextEdit,QFontDialog,QDialog,QWidget,QPushButton
from PyQt5.QtPrintSupport import QPageSetupDialog,QPrintDialog,QPrinter from
PyQt5.QtGui import QIcon import sys class Ui_test: def __init__(self):
self.creat_info() self.printer=QPrinter() def creat_info(self):
self.w=QWidget() self.w.setGeometry(400,400,500,500)
self.w.setWindowTitle(' Analog printer ') self.w.setWindowIcon(QIcon('res/nene.png'))
self.creat_res() self.w.show() def creat_res(self): self.t1=QTextEdit(self.w)
self.t1.setGeometry(15,15,300,400) self.B_openfile=QPushButton(' Open the file ',self.w)
self.B_openfile.setGeometry(350,15,100,30)
self.B_openmorefile=QPushButton(' Open multiple files ',self.w)
self.B_openmorefile.setGeometry(350,65,100,30)
self.B_change_font=QPushButton(' Modify font ',self.w)
self.B_change_font.setGeometry(350,115,100,30)
self.B_change_color=QPushButton(' Change color ',self.w)
self.B_change_color.setGeometry(350,165,100,30)
self.save_file=QPushButton(' Save the file ',self.w)
self.save_file.setGeometry(350,215,100,30)
self.set_page=QPushButton(' Page setup ',self.w)
self.set_page.setGeometry(350,265,100,30)
self.print_file=QPushButton(' Document printing ',self.w)
self.print_file.setGeometry(350,315,100,30)
self.clear_file=QPushButton(' Clear text ',self.w)
self.clear_file.setGeometry(350,365,100,30) self.config() def config(self):
self.B_openfile.clicked.connect(self.open_file)
self.B_openmorefile.clicked.connect(self.open_files)
self.B_change_color.clicked.connect(self.change_color)
self.B_change_font.clicked.connect(self.change_font)
self.clear_file.clicked.connect(self.clear_all)
self.save_file.clicked.connect(self.save_files)
self.set_page.clicked.connect(self.page_config)
self.print_file.clicked.connect(self.print_files) def clear_all(self):
self.t1.clear() def open_file(self):
files=QFileDialog.getOpenFileName(self.w,' Open local file ') if files[0]: with
open(files[0],mode='r',encoding='gb18030',errors='ignore') as f:
self.t1.setText(f.read()) def open_files(self):# Multiple documents are obtained here , A list of files is returned
files=QFileDialog.getOpenFileNames(self.w,' Open local file ') print(files) if files[0]:
for file in files[0]: with
open(file,mode='r',encoding='gb18030',errors='ignore') as f:
self.t1.append(f.read()) def change_font(self): fo,b=QFontDialog.getFont() if
b: self.t1.setCurrentFont(fo) def change_color(self):
co=QColorDialog.getColor() if co.isValid(): self.t1.setTextColor(co) def
save_files(self): file=QFileDialog.getSaveFileName(self.w,' Save the file ') if file[0]:
with open(file[0],mode='r',encoding='gb18030',errors='ignore') as f:
f.write(self.t1.toPlainText()) def page_config(self):
page_set=QPageSetupDialog(self.printer,self.w) page_set.exec_() def
print_files(self): page_print=QPrintDialog(self.w) if
QDialog.Accepted==page_print.exec_(): self.t1.print(self.printer)
ap=QApplication(sys.argv) u=Ui_test() sys.exit(ap.exec_())

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )java Four functional interfaces ( a key , simple )HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees os Simple use of module