博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PyQt5之QPrinter打印
阅读量:3958 次
发布时间:2019-05-24

本文共 1620 字,大约阅读时间需要 5 分钟。

PyQt5之QPrinter打印

import sysfrom PyQt5 import QtCorefrom PyQt5.QtWidgets import *from PyQt5.QtGui import *from PyQt5.QtCore import *from PyQt5.QtPrintSupport import QPageSetupDialog,QPrintDialog,QPrinterclass Win(QMainWindow):    def __init__(self):        super().__init__()        self.setGeometry(300, 300,500, 400)        self.setWindowTitle('QPrinter的使用')        self.printer = QPrinter()        self.editor = QTextEdit(self)        self.editor.setGeometry(20,20,300,270)        self.openButton = QPushButton('打开文件',self)        self.openButton.move(350,20)        self.settingsButton = QPushButton('打印设置',self)        self.settingsButton.move(350,50)        self.printButton = QPushButton('打印文档',self)        self.printButton.move(350,80)        self.openButton.clicked.connect(self.openFile)        self.settingsButton.clicked.connect(self.showSettingsDialog)        self.printButton.clicked.connect(self.showPrintDialog)        	#打开文件    def openFile(self):        frame = QFileDialog.getOpenFileName(self,'打开文本文件','./')        if frame[0]:            with open(frame[0],'r',encoding='utf-8',errors='ignore') as f:                self.editor.setText(f.read())                	#显示打印设置对话框    def showSettingsDialog(self):        printDialog = QPageSetupDialog(self.printer,self)        printDialog.exec()	#显示打印文档对话框    def showPrintDialog(self):        printDialog = QPrintDialog(self.printer,self)        if(QDialog.Accepted == printDialog.exec_()):            self.editor.print(self.printer)if __name__ == "__main__":    app = QApplication(sys.argv)    form = Win()    form.show()    sys.exit(app.exec_())

运行效果如下:

在这里插入图片描述

在这里插入图片描述

转载地址:http://utozi.baihongyu.com/

你可能感兴趣的文章
js类型转换
查看>>
spring实例化Bean理解
查看>>
Mac下配置JAVA_HOME
查看>>
fedora 安装mp3播放器插件
查看>>
赏心悦目的宏代码
查看>>
理解套接字recv(),send()
查看>>
发一个C++写的跨平台的BlockingQueue
查看>>
Linux TCP/IP协议栈剖析【体系结构篇】
查看>>
游戏开发中预防内存泄露的一些措施
查看>>
以前的文章全部移除了。
查看>>
几首歌
查看>>
蝴蝶泉边
查看>>
编码转换
查看>>
freerice
查看>>
Does your mother know
查看>>
《写出质量好软件的75条体会》暨答案ZT [转自monkyy的blog]
查看>>
关于详细设计
查看>>
POJ2838,Sliding Window(单调队列)
查看>>
牛客练习赛50,B tokitsukaze and Hash Table(STL+输入输出挂)
查看>>
POJ3728,The merchant(倍增LCA+分治)
查看>>