程序示例精选
Python+Qt画图板-手写板
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对《Python+Qt画图板-手写板》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
运行结果
文章目录
一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助
一、所需工具软件
1. Python
2. Pycharm
二、使用步骤
代码如下(示例):
def paintBoardChangeH(self):
comboBoxTEXT=self.comboBox_3.currentText()
print("TEXT",comboBoxTEXT)
global paintBoardHeight
global paintBoardWidth
if comboBoxTEXT=="1000x1000":
paintBoardHeight=1000
paintBoardWidth=1000
if comboBoxTEXT=="A5_241x148":
paintBoardHeight=148
paintBoardWidth=241
if comboBoxTEXT=="A3_420x297":
paintBoardHeight=297
paintBoardWidth=420
if comboBoxTEXT=="A2_594x420":
paintBoardHeight=420
paintBoardWidth=594
if comboBoxTEXT=="A1_841x594":
paintBoardHeight=594
paintBoardWidth=841
print("paintBoardHeight-button", paintBoardHeight)
print("paintBoardWidth-button", paintBoardWidth)
self.__paintBoard.setGeometry(0, 0, paintBoardWidth, paintBoardHeight)
#将按钮选择的新的画板尺寸传递到painboard.py
self.__paintBoard.paintBoardSizeT(paintBoardWidth,paintBoardHeight)
#初始化画板
self.clear_paintboard()
def clear_paintboard(self):
self.__paintBoard.clear()
def change_pen_color(self):
color_index = self.comboBox.currentIndex()
#橡皮选不选中的绑定函数
def on_cbtn_Eraser_clicked(self):
print("on_cbtn_Eraser_clicked")
if self.checkBox.isChecked():
self.__paintBoard.change_eraser_mode = True #进入橡皮擦模式
else:
self.__paintBoard.change_eraser_mode = False #退出橡皮擦模式
#撤销上一条线
def on_btn_undoLastLine_Clicked(self):
print("on_btn_undoLastLine_Clicked")
#self.undoLastLine()
try:
self.__paintBoard.undoLastLine()
except Exception as e:
print(f"An error occurred: {e}")
# 删除最后一行文本
with open("coordinates.txt", "r") as file:
lines = file.readlines()
if lines:
lines = lines[:-1] # 删除最后一行
with open("coordinates.txt", "w") as file:
file.writelines(lines)
#恢复上一条线
def on_btn_redoLastLine_Clicked(self):
print("on_btn_redoLastLine_Clicked")
try:
self.__paintBoard.redoLastLine()
except Exception as e:
print(f"An error occurred: {e}")
#功能函数开始 画笔颜色************************************************
def __fillColorList(self, comboBox):
index_black = 0
index = 0
for color in self.__colorList:
if color == "black":
index_black = index
index += 1
pix = QPixmap(70,20)
pix.fill(QColor(color))
comboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents)
comboBox.setCurrentIndex(index_black)
#颜色选择的函数
def on_PenColorChange(self):
color_index = self.comboBox.currentIndex()
color_str = self.__colorList[color_index]
#画笔粗细改变的函数
def on_PenThicknessChange(self):
self.__paintBoard.change_pen_thickness(penThickness)
def on_btn_Save_Clicked(self):
savePath = QFileDialog.getSaveFileName(self, 'Save Your Paint', '.\\', '*.png')
print(savePath)
if savePath[0] == "":
print("Save cancel")
# image = self.__paintBoard.GetContentAsQImage()
# image.save(savePath[0])
# print(savePath[0])
def Quit(self):
self.close()
运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作
当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页:https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog
博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别:https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445
Python+Yolov5道路障碍物识别:https://blog.csdn.net/alicema1111/article/details/129589741
Python+Yolov5跌倒检测 摔倒检测 人物目标行为 人体特征识别:https://blog.csdn.net/alicema1111/article/details/129272048