Python tablet drawing board signature tool

Featured program examples

Python tablet drawing board signature tool

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!

foreword

This blog writes code for <<Python handwriting board drawing board signature tool>>, the code is neat, regular and easy to read. The first choice for learning and application recommendation.


Article directory

1. Required tool software

2. Use steps

        1. Import library

        2. Code implementation

       3. Running results

3. Online assistance

1. Required tool software

1. Python

2. Qt, OpenCV

2. Use steps

1. Import library

# coding:utf-8
import sys
#从转换的.py文件内调用类
import cv2

from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

from PyQt5.uic import loadUi

from PaintBoard import PaintBoard
from PyQt5.Qt import QColor,QPixmap,QComboBox,QSize,QIcon,QCheckBox

2. Code implementation

code show as below:

class myWin(QtWidgets.QMainWindow,Ui_MainWindow):

    def __init__(self):
        super(myWin, self).__init__()
        #self.ui = loadUi('untitled.ui')
        self.setupUi(self)

        self.pushButton.clicked.connect(self.on_login)


        self.InitPaintBoard()  # 先初始化数据,再初始化界面

    # 初始化画板
    def InitPaintBoard(self):
        # self.__paintBoard = PaintBoard(self) #这句是连接生成画板到界面上

        #新加的代码
        self.__paintBoard = PaintBoard(self) #这句是连接生成画板到界面上
        paintboardlayout=QtWidgets.QVBoxLayout(self)
        self.groupBox.setLayout(paintboardlayout)
        paintboardlayout.addWidget(self.__paintBoard)

        #新加显示颜色下拉的代码
        #获取颜色列表(字符串类型)
        self.__colorList = QColor.colorNames()
        self.__fillColorList(self.comboBox)


        #绑定橡皮,粗细,颜色选择信号
        self.checkBox.clicked.connect(self.on_cbtn_Eraser_clicked)
        self.spinBox.valueChanged.connect(self.on_PenThicknessChange)#关联spinBox值变化信号和函数on_PenThicknessChange
        self.comboBox.currentIndexChanged.connect(self.on_PenColorChange) #关联下拉列表的当前索引变更信号与函数on_PenColorChange

        #将按键按下信号与画板清空函数相关联
        self.pushButton.clicked.connect(self.__paintBoard.Clear)
        self.pushButton_2.clicked.connect(self.Quit)
        self.pushButton_3.clicked.connect(self.on_btn_Save_Clicked)


    #功能函数开始************************************************
    def __fillColorList(self, comboBox):

        index_black = 0
        index = 0
        for color in self.__colorList:
            if color == "black":
                index_black = index

            comboBox.setIconSize(QSize(70,20))
            comboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents)

        comboBox.setCurrentIndex(index_black)

    #橡皮选不选中的绑定函数
    def on_cbtn_Eraser_clicked(self):
        if self.checkBox.isChecked():
            self.__paintBoard.EraserMode = True #进入橡皮擦模式
        else:
            self.__paintBoard.EraserMode = False #退出橡皮擦模式
    #颜色选择的函数
    def on_PenColorChange(self):
        color_index = self.comboBox.currentIndex()
        color_str = self.__colorList[color_index]
        self.__paintBoard.ChangePenColor(color_str)



    def on_btn_Save_Clicked(self):
        savePath = QFileDialog.getSaveFileName(self, 'Save Your Paint', '.\\', '*.png')
        print(savePath)
        if savePath[0] == "":
            print("Save cancel")
            return
        image = self.__paintBoard.GetContentAsQImage()
        image.save(savePath[0])
        print(savePath[0])

    def Quit(self):
        self.close()

    # 功能函数结束************************************************

    def on_login(self):
        print("test")

if __name__=="__main__":

    app=QtWidgets.QApplication(sys.argv)
    Widget=myWin()
    Widget.showMaximized();
    sys.exit(app.exec_())

3. Running results

 

3. Online assistance:

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!
1) Remote installation and operation environment, code debugging
2) Qt, C++, Python entry guide
3) Interface beautification
4) Software production

Blogger recommended article: python face recognition statistics qt form - CSDN Blog

Blogger recommended article: Python Yolov5 flame smoke recognition source code sharing - CSDN blog

Personal blog homepage: alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Click here for all the blogger's articles: alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Guess you like

Origin blog.csdn.net/alicema1111/article/details/130141002