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

相关推荐
BoBoZz192 小时前
MultipleRenderWindows 创建多个渲染窗口
python·vtk·图形渲染·图形处理
津津有味道3 小时前
Python写入URI网址到Ntag 424 DNA标签配置开启动态UID计数器镜像
linux·python·nfc·动态uid·424·cma加密数据
2401_841495643 小时前
【Python高级编程】Python 核心语法速查演示
python·字符串·集合·列表·元组·字典·运算符
2301_811958383 小时前
服务器自己账号下安装conda
linux·python·conda
百***78753 小时前
Mistral 3极速接入指南:3步上手+核心能力解析+避坑手册
人工智能·python·开源
LCG米4 小时前
嵌入式Python开发:MicroPython在物联网硬件上的实战应用案例
python·单片机·物联网
nvd114 小时前
SQLAlchemy 2.0 类型注解指南:`Mapped` 与 `mapped_column`
python
让学习成为一种生活方式4 小时前
AGAT v1.6.0 安装与使用--生信工具72
人工智能·python·机器学习
小陈phd4 小时前
Python MCP 工具开发入门:Server、Client 和 LLM 集成
开发语言·python·github