PyQT5云打印GUI设计
2021/4/18 10:27:20
本文主要是介绍PyQT5云打印GUI设计,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
PyQT5云打印GUI设计
打印机部分由win32编写,Mac系统通通注释掉,哈哈哈,我也没测可以不可以用,学长给的函数
Widget.py
from PyQt5.QtGui import QFont, QPixmapfrom PyQt5.QtWidgets import QWidget, QLabel, QLineEdit, QComboBox, QGridLayout, QPushButton, QTableWidget, \ QAbstractItemView, QRadioButton# import win32print as PrinterOperaterclass UI(QWidget):def __init__(self):super().__init__()self.initUI()def initUI(self):grid = QGridLayout()grid.setSpacing(10)label1 = QLabel(self)label2 = QLabel(self)label3 = QLabel(self)font1 = QFont("Arial", 17, QFont.Black)label1.setText('系统当前默认打印机:')label1.setFont(font1)label2.setText('修改系统默认打印机:')label2.setFont(font1)label1_edit = QLineEdit(self)label1_edit.setReadOnly(True)# allPrinters = PrinterOperater.EnumPrinters(2)label2_edit = QComboBox(self)# label2_edit.addItem(allPrinters)font2 = QFont("Arial", 14, QFont.Black)btn1 = QPushButton(self)btn2 = QPushButton(self)btn3 = QPushButton(self)btn1.setFont(font2)btn2.setFont(font2)btn3.setFont(font2)btn1.setText('获取系统所有可用打印机')btn2.setText('选取当前打印机为默认打印机')btn3.setText("刷新打印列表")# btn1.clicked.connect(self.getAllPrinters)# btn2.clicked.connect(self.getDefaultPrinter)# btn3.clicked.connect(self.getAllJobs)Table = QTableWidget(20, 5)Row_name = ['任务编号','任务名称','文件页数','打印状态','备注',]Table.setHorizontalHeaderLabels(Row_name)Table.setEditTriggers(QAbstractItemView.NoEditTriggers)image = QPixmap('images/image.png')label3.setPixmap(image)CheckBox1 = QRadioButton('上线营业')CheckBox2 = QRadioButton('暂停营业')CheckBox1.setChecked(True)CheckBox1.toggled.connect(lambda: self.btnstate(CheckBox1))CheckBox1.toggled.connect(lambda: self.btnstate(CheckBox2))grid.addWidget(label1, 1, 0)grid.addWidget(label1_edit, 1, 1)grid.addWidget(btn1, 1, 2, 1, 2)grid.addWidget(label2, 2, 0)grid.addWidget(label2_edit, 2, 1)grid.addWidget(btn2, 2, 2, 1, 2)grid.addWidget(btn3, 3, 2, 1, 2)grid.addWidget(Table, 3, 0, 5, 2)grid.addWidget(label3, 5, 2)grid.addWidget(CheckBox1, 6, 2)grid.addWidget(CheckBox2, 7, 2)self.setLayout(grid)def btnstate(self, btn):# 输出按钮1与按钮2的状态,选中还是没选中if btn.text() == '上线营业':if btn.isChecked() == True:print(btn.text() + "is selected")else:print(btn.text() + "is deselected")if btn.text() == "暂停营业":if btn.isChecked() == True:print(btn.text() + "is selected")else:print(btn.text() + "is deselected")# def getDefaultPrinter(self):# defaultPrinter = PrinterOperater.GetDefaultPrinter()## print(defaultPrinter)## def getAllJobs(self):# defaultPrinter = PrinterOperater.GetDefaultPrinter()# PyPrinterHANDLE = PrinterOperater.OpenPrinter(defaultPrinter)# allPrintJobs = PrinterOperater.EnumJobs(PyPrinterHANDLE, 0, 15, 1)## print(allPrintJobs)## def setDefaultPrinter(self):# tempPrinter = sys.argv[1];## PrinterOperater.SetDefaultPrinter(tempPrinter)## defaultPrinter = PrinterOperater.GetDefaultPrinter()## print(defaultPrinter)
MainWindow.py
from PyQt5.QtWidgets import QDesktopWidget, QMessageBoxfrom Widget import UIclass MainWindow(UI):def __init__(self):super().__init__()self.showWindow()def showWindow(self):self.resize(720, 640)self.setWindowTitle('云打印服务系统(商家版)-桌面版')self.center()self.show()def center(self):qr = self.frameGeometry()cp = QDesktopWidget().availableGeometry().center()qr.moveCenter(cp)self.move(qr.topLeft())def closeEvent(self, QCloseEvent):reply = QMessageBox.question(self, 'Message', "你确定退出系统吗?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)if reply == QMessageBox.Yes:QCloseEvent.accept()else:QCloseEvent.ignore()
Main.py
import sysfrom PyQt5.QtWidgets import QApplicationfrom MainWindow import MainWindowif __name__ == '__main__':app = QApplication(sys.argv)Window = MainWindow()sys.exit(app.exec_())
这篇关于PyQT5云打印GUI设计的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22项目:远程温湿度检测系统
- 2024-12-21《鸿蒙HarmonyOS应用开发从入门到精通(第2版)》简介
- 2024-12-21后台管理系统开发教程:新手入门全指南
- 2024-12-21后台开发教程:新手入门及实战指南
- 2024-12-21后台综合解决方案教程:新手入门指南
- 2024-12-21接口模块封装教程:新手必备指南
- 2024-12-21请求动作封装教程:新手必看指南
- 2024-12-21RBAC的权限教程:从入门到实践
- 2024-12-21登录鉴权实战:新手入门教程
- 2024-12-21动态权限实战入门指南