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

相关推荐
寻星探路2 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
ValhallaCoder5 小时前
hot100-二叉树I
数据结构·python·算法·二叉树
猫头虎5 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
八零后琐话6 小时前
干货:程序员必备性能分析工具——Arthas火焰图
开发语言·python
青春不朽5127 小时前
Scrapy框架入门指南
python·scrapy
MZ_ZXD0018 小时前
springboot旅游信息管理系统-计算机毕业设计源码21675
java·c++·vue.js·spring boot·python·django·php
全栈老石8 小时前
Python 异步生存手册:给被 JS async/await 宠坏的全栈工程师
后端·python
梨落秋霜8 小时前
Python入门篇【模块/包】
python
阔皮大师9 小时前
INote轻量文本编辑器
java·javascript·python·c#