python中locateCenterOnScreen的confidence错误

运行pyautogui.locateCenterOnScreen函数时弹出TypeError错误,原因是缺少组件。通过执行“pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python”命令安装opencv-python,即可解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

运行pyautogui.locateCenterOnScreen(r'C:\Users\Administrator\desktop\python\bjh_zhijiefabu.png' , grayscale=False, confidence=0.7),会弹出错误,TypeError: _locateAll_python() got an unexpected keyword argument 'confidence’。

原因是少组件

“pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python”,安装好opencv-python。就可以解决问题

下面这个代码里面的pyautogui.locateCenterOnScreen(img, confidence=0.9)在这个片段运行有问题错误是Parameter(s) unfilledPossible callees:locateCenterOnScreen(image: str | Image, *, minSearchTime: float, grayscale: bool | None = None, limit: object = 1, region: tuple[int, int, int, int] | None = None, step: int = 1, confidence: SupportsFloat | SupportsIndex | str | Buffer | Buffer = 0.999)locateCenterOnScreen(image: str | Image, *, minSearchTime: float, grayscale: bool | None = None, limit: object = 1, region: tuple[int, int, int, int] | None = None, step: int = 1, confidence: None = None),请给出修改无误后的代码def mouseClick(click_times, lOrR, img, re_try): """ 定义鼠标事件 :param click_times: :param lOrR: :param img: :param re_try: :return: """ if re_try == 1: while True: location = pyautogui.locateCenterOnScreen(img, confidence=0.9) if location is not None: pyautogui.click(location.x, location.y, clicks=click_times, interval=0.2, duration=0.2, button=lOrR) break print("未找到匹配图片,0.1秒后重试") time.sleep(0.1) elif re_try == -1: while True: location = pyautogui.locateCenterOnScreen(img, confidence=0.9) if location is not None: pyautogui.click(location.x, location.y, clicks=click_times, interval=0.2, duration=0.2, button=lOrR) time.sleep(0.1) elif re_try > 1: i = 1 while i < re_try + 1: location = pyautogui.locateCenterOnScreen(img, confidence=0.9) if location is not None: pyautogui.click(location.x, location.y, clicks=click_times, interval=0.2, duration=0.2, button=lOrR) print("重复") i += 1 time.sleep(0.1)
03-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值