LabelImg使用时报错:TypeError: setValue(self, val: int)

项目场景:

TypeError: setValue(self, val: int): argument 1 has unexpected type 'float'

使用LabelImg时突然间报错了


问题描述

突然的报错让我很意外,怎么会突然报错呢,下面是报错原因

c 复制代码
Traceback (most recent call last):
  File "D:\miniconda\envs\mm\lib\site-packages\labelImg\labelImg.py", line 1014, in zoom_request
    self.add_zoom(scale * units)
  File "D:\miniconda\envs\mm\lib\site-packages\labelImg\labelImg.py", line 974, in add_zoom
    self.set_zoom(self.zoom_widget.value() + increment)
  File "D:\miniconda\envs\mm\lib\site-packages\labelImg\labelImg.py", line 971, in set_zoom
    self.zoom_widget.setValue(value)
TypeError: setValue(self, val: int): argument 1 has unexpected type 'float'

原因分析:

这个错误是因为在调用 drawLine 函数时传入了一个浮动类型(float)的参数,而该函数期望的是整数类型(int)或其他合适的类型(如 QPoint 或 QLine)。


解决方案:

按照报错上面的路径打开到canvas.py文件,右击选择打开方式-->记事本,接着搜索drawLine,可以发现有两行都使用了这个函数,全部修改:

python 复制代码
p.drawLine(int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))
p.drawLine(0, int(self.prev_point.y()), self.pixmap.width(), int(self.prev_point.y()))

这个文件还有一处要修改

python 复制代码
p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))

完成之后再次运行,发现还会报错,接着继续修改。

按照报错路径,找到labelImg.py文件,同样的方式,右击选择打开方式-->记事本,不同的是搜索bar.setValue,更改,保存:

python 复制代码
bar.setValue(int(bar.value() + bar.singleStep() * units))

至此,重新打开LabelImg,成功可以使用!

相关推荐
梨子串桃子_1 天前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法
文言一心1 天前
LINUX离线升级 Python 至 3.11.9 操作手册
linux·运维·python
诗词在线1 天前
中国古代诗词名句按主题分类有哪些?(爱国 / 思乡 / 送别)
人工智能·python·分类·数据挖掘
高锰酸钾_1 天前
机器学习-L1正则化和L2正则化解决过拟合问题
人工智能·python·机器学习
天天睡大觉1 天前
Python学习11
网络·python·学习
智航GIS1 天前
11.11 Pandas性能革命:向量化操作与内存优化实战指南
python·pandas
写代码的【黑咖啡】1 天前
Python中的Selenium:强大的浏览器自动化工具
python·selenium·自动化
抠头专注python环境配置1 天前
解决Windows安装PythonOCC报错:从“No module named ‘OCC’ ”到一键成功
人工智能·windows·python·3d·cad·pythonocc
华研前沿标杆游学1 天前
2026年华研就业实践营|走进字节跳动,解锁科技行业职业新航向
python