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,成功可以使用!

相关推荐
徒 花15 小时前
Python知识学习08
java·python·算法
前端技术15 小时前
ArkTS第三章:声明式UI开发实战
java·前端·人工智能·python·华为·鸿蒙
疯狂成瘾者16 小时前
.pyc格式文件
python
鬼圣16 小时前
Python 生成器与迭代器详解
python
西魏陶渊明16 小时前
解决异步挑战:Reactor Context 实现响应式上下文传递
开发语言·python
疯狂成瘾者16 小时前
增强型大模型代理
python
小李云雾16 小时前
FastAPI 后端开发:文件上传 + 表单提交
开发语言·python·lua·postman·fastapi
Legend NO2416 小时前
数据资产评估风险识别、分析与管控体系建设
大数据·人工智能·python
llm大模型算法工程师weng16 小时前
Python敏感词检测方案详解
开发语言·python·c#
Ricky111zzz16 小时前
leetcode学python记录2
python·算法·leetcode·职场和发展