PyQt是Qt框架的Python语言实现,是最强大的GUI库之一。PyQt提供了一个设计良好的窗口控件集合,具有更方便的操作性。学过VB的同学会知道,相比与VB的使用,在界面设计上元素更丰富。
本文就是基于PyQt5完成的图转文功能,先看界面:
一、界面PicZ.ui可参考之前的文章如何实现,程序代码如下:
from PyQt5 import QtCore, QtGui, QtWidgets
import base64
import os
from return_png import img as retu # 引入img变量,赋别名为pdf_cf
class Ui_PicZ(object):
def setupUi(self, PicZ):
tmp = open('return.png', 'wb') # 创建临时的文件
tmp.write(base64.b64decode(retu)) # 把这个one图片解码出来,写入文件中去。
tmp.close()
PicZ.setObjectName("PicZ")
PicZ.resize(1400, 814)
PicZ.setMinimumSize(QtCore.QSize(1400, 814))
PicZ.setMaximumSize(QtCore.QSize(1400, 814))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
PicZ.setPalette(palette)
self.Reback = QtWidgets.QToolButton(PicZ)
self.Reback.setGeometry(QtCore.QRect(10, 10, 51, 41))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush)
self.Reback.setPalette(palette)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("return.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)