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打印机的更多相关文章

  1. Python调用打印机参考例子

    参考资料: http://blog.csdn.net/jdh99/article/details/42585987 http://www.oschina.net/question/1438043_23 ...

  2. 清除打印机队列中无法清除的任务 & 清空打印池

    故障现象典型表现为以下两种情况 1.当打印任务开始进行时,这些打印任务便被保存在打印作业列表(也称打印队列)内.如果打印机因意外暂停(如打印机未连接)而未完成打印任务,则该打印任务将列入打印队列,并且 ...

  3. 用 eric6 与 PyQt5 实现python的极速GUI编程(系列04)---- PyQt5自带教程:地址簿(address book)

    [引子] 在PyQt5自带教程中,地址簿(address book)程序没有完全实现界面与业务逻辑分离. 本文我打算用eric6+PyQt5对其进行改写,以实现界面与逻辑完全分离. [概览] 1.界面 ...

  4. Java jacob调用打印机打印word文档

    前面说了Java如何生成复杂的Word文档,今年记录下Java如何调用打印机打印word文档. 起初用的是自带的PrintJob,但是系统提供的打印机制并不成熟完整.网上的代码也是千篇一律,在我的打印 ...

  5. Java使用POS打印机(无驱)

    使用原因:应项目要求,需要使用打印机,但是如果使用Windows驱动来实现打印,在某些条件下会发生网络堵塞等,而且没有提示,所以为了确保信息的完整,避免数据丢失.我们使用无驱打印(直接写端口的方法), ...

  6. PDF虚拟打印机

    1.安装福昕PDF阅读器,自己就会安装上PDF虚拟打印机 2.通过office2010之后版本中自带的另存为功能转换为pdf 3.pdf虚拟打印机工具:工具1:http://www.win2pdf.c ...

  7. HP网络打印机--如何添加打印机

    HP网络打印机采用web服务形式,应添加打印机-通过Internet的打印机--填写网址http://192.168.1.10:80(从其他win7电脑-计算机-网络-网络设备中双击添加打印机,然后在 ...

  8. PyQt5+Python3.5.2-32bit开发环境搭建

      1.基本环境. Window 8.1 64bit Python3.5.2-32bit.exe PyQt5 2.安装python. 去官网下载32位版本的python3.5.2(就是x86那个) 备 ...

  9. Windows远程桌面打印机映射

    计算机的打印机驱动能打印,需要满足两个条件,一个是有打印驱动本身,一个是要有连接好了的端口.这样,打印作业就会被打印驱动程序封装成一种打印机能识别的组织形式,然后通过打印端口发送给打印机,然后打印! ...

随机推荐

  1. beego 页面布局

    模板 this.Layout = "admin/layout.html" this.TplName = "admin/list.html" 在layout.ht ...

  2. Spark 中 GroupByKey 相对于 combineByKey, reduceByKey, foldByKey 的优缺点

    避免使用GroupByKey 我们看一下两种计算word counts 的方法,一个使用reduceByKey,另一个使用 groupByKey: val words = Array("on ...

  3. WLC5520分布式端口(数据口)使用1G模块!

    思科WLC5520有两个分布式端口.  在 10G 模式和 1G 模式之间切换•如果在端口 1 上未安装任何内容,则默认情况下主板配置为 10G 模式.因此,要切换到 1G 模式,则必须在端口 1上安 ...

  4. vue中style下scope的使用和坑

    在vue组件中,为了使样式私有化(模块化),不对全局造成污染,可以在style标签上添加scoped属性以表示它的只属于当下的模块,这是一个非常好的举措,但是为什么要慎用呢?因为在我们需要修改公共组件 ...

  5. ASP学习笔记1

    一.变量 1.1 声明变量 dim name name="Donald Duck" response.write("My name is: " & na ...

  6. C#中通过SendARP读取MAC地址

    C#中通过SendARP读取MAC地址: using System.Runtime.InteropServices; publicstaticstring GetMacBySendARP(string ...

  7. iview渲染函数

    <Table border :columns="discountColumns" :data="discountData.rows"></Ta ...

  8. Git的基本使用 -- 创建本地仓库

    下载安装 Git-2.25.0-64-bit .exe 查看是否安装成功 git --version 创建本地仓库 创建一个文件夹用于存放项目文件 在创建好的文件中右键选择 Git Bash Here ...

  9. AcWing 850. Dijkstra求最短路 II 堆优化版 优先队列 稀疏图

    //稀疏图 点和边差不多 #include <cstring> #include <iostream> #include <algorithm> #include ...

  10. Vue 高德地图 路径规划 画点

    CDN 方式 <!--引入高德地图JSAPI --> <script src="//webapi.amap.com/maps?v=1.4.13&key=您申请的ke ...