PyQt5打印机
1、打印机操作(打印默认文本里面的内容)
from PyQt5 import QtGui,QtWidgets,QtPrintSupport
from PyQt5.QtWidgets import *
import sys class Printsupport1(QMainWindow):
def __init__(self):
super(Printsupport1,self).__init__()
self.setGeometry(500,200,300,300)
self.button=QPushButton("打印QtextEdit控件中的内容",self)
self.button.setGeometry(20,60,260,200)
self.editor=QTextEdit("默认文本",self)
self.button.clicked.connect(self.print) def print(self):
printer=QtPrintSupport.QPrinter() #打印机 painter=QtGui.QPainter()
#将绘制的目标重新定向到打印机
painter.begin(printer)
screen=self.editor.grab()
painter.drawPixmap(10,10,screen)
painter.end()
print("print") if __name__=="__main__":
app=QApplication(sys.argv)
p=Printsupport1()
p.show()
sys.exit(app.exec_())

2、显示打印样式设置对话框
from PyQt5.QtPrintSupport import QPageSetupDialog,QPrintDialog,QPrinter
from PyQt5.QtWidgets import *
import sys class Printdialog(QMainWindow):
def __init__(self):
super(Printdialog,self).__init__()
self.printer=QPrinter() #定义一个默认的打印机
self.initUI() def initUI(self):
self.setGeometry(300,300,500,400)
self.setWindowTitle("打印对话框")
self.editor=QTextEdit(self)
self.editor.setGeometry(20,20,300,270) self.openbutton=QPushButton("打开文件",self)
self.openbutton.move(350,20) self.settingbutton=QPushButton("打印设置",self)
self.settingbutton.move(350,50) self.printbutton=QPushButton("打印文档",self)
self.printbutton.move(350,80) self.openbutton.clicked.connect(self.openfile)
self.settingbutton.clicked.connect(self.showsettingdailog)
self.printbutton.clicked.connect(self.showprintdialog)
#打开文件
def openfile(self):
fname=QFileDialog.getOpenFileName(self,"打开文本文件","./")
if fname[0]:
with open(fname[0],"r",encoding='utf-8',errors='ignore') as f:
self.editor.setText(f.read()) #显示打印设置对话框
def showsettingdailog(self):
printerdailog=QPageSetupDialog(self.printer,self)
printerdailog.exec() #显示打印对话框
def showprintdialog(self):
print1=QPrintDialog(self.printer,self)
if QDialog.Accepted==print1.exec():
self.editor.print(self.printer) if __name__=="__main__":
app=QApplication(sys.argv)
p=Printdialog()
p.show()
sys.exit(app.exec_())

PyQt5打印机的更多相关文章
- Python调用打印机参考例子
参考资料: http://blog.csdn.net/jdh99/article/details/42585987 http://www.oschina.net/question/1438043_23 ...
- 清除打印机队列中无法清除的任务 & 清空打印池
故障现象典型表现为以下两种情况 1.当打印任务开始进行时,这些打印任务便被保存在打印作业列表(也称打印队列)内.如果打印机因意外暂停(如打印机未连接)而未完成打印任务,则该打印任务将列入打印队列,并且 ...
- 用 eric6 与 PyQt5 实现python的极速GUI编程(系列04)---- PyQt5自带教程:地址簿(address book)
[引子] 在PyQt5自带教程中,地址簿(address book)程序没有完全实现界面与业务逻辑分离. 本文我打算用eric6+PyQt5对其进行改写,以实现界面与逻辑完全分离. [概览] 1.界面 ...
- Java jacob调用打印机打印word文档
前面说了Java如何生成复杂的Word文档,今年记录下Java如何调用打印机打印word文档. 起初用的是自带的PrintJob,但是系统提供的打印机制并不成熟完整.网上的代码也是千篇一律,在我的打印 ...
- Java使用POS打印机(无驱)
使用原因:应项目要求,需要使用打印机,但是如果使用Windows驱动来实现打印,在某些条件下会发生网络堵塞等,而且没有提示,所以为了确保信息的完整,避免数据丢失.我们使用无驱打印(直接写端口的方法), ...
- PDF虚拟打印机
1.安装福昕PDF阅读器,自己就会安装上PDF虚拟打印机 2.通过office2010之后版本中自带的另存为功能转换为pdf 3.pdf虚拟打印机工具:工具1:http://www.win2pdf.c ...
- HP网络打印机--如何添加打印机
HP网络打印机采用web服务形式,应添加打印机-通过Internet的打印机--填写网址http://192.168.1.10:80(从其他win7电脑-计算机-网络-网络设备中双击添加打印机,然后在 ...
- PyQt5+Python3.5.2-32bit开发环境搭建
1.基本环境. Window 8.1 64bit Python3.5.2-32bit.exe PyQt5 2.安装python. 去官网下载32位版本的python3.5.2(就是x86那个) 备 ...
- Windows远程桌面打印机映射
计算机的打印机驱动能打印,需要满足两个条件,一个是有打印驱动本身,一个是要有连接好了的端口.这样,打印作业就会被打印驱动程序封装成一种打印机能识别的组织形式,然后通过打印端口发送给打印机,然后打印! ...
随机推荐
- selenium grid的使用
Selenium grid是用来分布式执行测试用例脚本的工具,比如测试人员经常要测试多浏览器的兼容性,那就可以用到grid了. selenium grid的hub相当于一个接收脚本并分发脚本的角色,n ...
- SpringBoot 各层之间的关系
SpringBoot 各层之间的关系 SpringBoot 分为四层:controller层.service层.dao层.entity层. entity层:和 model 层一样,存放的是实体类,属 ...
- How To Use These LED Garden Lights
Are you considering the lighting options for the outdoor garden? Depending on how you use it, LED ga ...
- pocketsphinx实现连续大词汇量语音识别
之前有个项目需求是要在客户内网实现一个连续大词汇语音识别功能,由于客户的内网是独立的,不能访问互联网,所以我只能到开源社区去找找碰碰运气了.后来在网上找到了cmusphinx(地址:http://cm ...
- Go性能调优
文章引用自 Go性能调优 在计算机性能调试领域里,profiling 是指对应用程序的画像,画像就是应用程序使用 CPU 和内存的情况. Go语言是一个对性能特别看重的语言,因此语言中自带了 pr ...
- 删除数据高级用法:delete,truncate
1.语法: delete 允许使用条件(删除符合条件的数据) 允许使用limit,限制删除的记录数.limit N 常见的是,limit配合order by来使用:先将结果排序,再删除固定数量 ...
- Flutter 开发入门实践
前言: Flutter 是 Google 推出的跨平台解决方案, 开发语言:Dart 优势: 劣势: 学习推荐: 官方网站:https://flutter.io/ 书籍:<Flutter技术入门 ...
- putty上传下载文件
一,需要pscp.exe,习惯上和Putty.exe文件放在一起. 首先需要保证在命令行下可以访问到pscp.exe.可以通过配置Windows的环境变量Path,或者直接通过命令行访问到pscp.e ...
- PHP5中__get()、__set()方法
标题是:PHP5中__get().__set()方法,不错,在PHP5以下(PHP4)是没有这两个方法的. __get()方法:这个方法用来获取私有成员属性值的,有一个参数,参数传入你要获取的成员属性 ...
- HBuilder笔记
官网: https://uniapp.dcloud.io/quickstart HBuilderX - 高效极客技巧 https://ask.dcloud.net.cn/article/13191 插 ...