Monica_MTF 2022-10-30 16:29 采纳率: 73.9%
浏览 408
已结题

类型错误TypeError: 'NoneType' object is not subscriptable怎么解决?

原本是想用AutoPyGUI写一个健康打卡脚本的,遇到如下错误。

源程序:

import pyautogui

pyautogui.click(x=1850, y=285)  #移动鼠标,然后点击
pyautogui.click(clicks=2, interval=0.25)    #双击,间隔秒数

import pyscreeze
# im1 = pyscreeze.screenshot()
# im2 = pyscreeze.screenshot('my_screenshot.png')
# for i in pyautogui.locateAllOnScreen('HKU.png'):
# list(pyautogui.locateAllOnScreen('HKU.png'))
# pyautogui.locateOnScreen('looksLikeThis.png')
pyautogui.screenshot('HKU.png')  # returns a Pillow/PIL Image object, and saves it to a file
# <PIL.Image.Image image mode=RGB size=1920x1080 at 0x31AA198>

buttonlocation = pyautogui.locateOnScreen('D:\VScode\HKU.png')
# buttonlocation = pyautogui.locateOnScreen('D:\VScode\微服务.png')
# buttonlocation = pyautogui.locateOnScreen('D:\VScode\服务平台.png')
# buttonlocation = pyautogui.locateOnScreen('D:\VScode\健康打卡.png')
# pyautogui.scroll(-10)  # scroll down 10 "clicks"

# buttonlocation = pyautogui.locateOnScreen('D:\VScode\更改.png')

# # pyautogui.scroll(-10)  # scroll down 10 "clicks"

# buttonlocation = pyautogui.locateOnScreen('D:\VScode\确认.png')

# # pyautogui.scroll(-10)  # scroll down 10 "clicks"

# # pyautogui.write('36.3', interval=0.25)  # prints out "Hello world!" with a quarter second delay after each character

# buttonlocation = pyautogui.locateOnScreen('D:\VScode\提交.png')
# buttonlocation = pyautogui.locateOnScreen('D:\VScode\确认2.png')
# buttonlocation = pyautogui.locateOnScreen('D:\VScode\确认2.png')
buttonpoint = pyautogui.center(buttonlocation)
buttonx, buttony = buttonpoint
pyautogui.click(buttonx, buttony)  

提示错误:


```python
Traceback (most recent call last):
  File "d:\VScode\AutoHKU.py", line 34, in <module>
    buttonpoint = pyautogui.center(buttonlocation)
  File "C:\Users\(用户名)\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 582, in center
    return Point(coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))
TypeError: 'NoneType' object is not subscriptable

类型错误:“空类型”目标不是下标,但代码行没有下标啊。

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月15日
  • 创建了问题 10月30日

悬赏问题

  • ¥15 Apache显示系统错误3该如何解决?
  • ¥30 uniapp小程序苹果手机加载gif图片不显示动效?
  • ¥20 js怎么实现跨域问题
  • ¥15 C++dll二次开发,C#调用
  • ¥15 请教,如何使用C#加载本地摄像头进行逐帧推流
  • ¥15 Python easyocr无法顺利执行,如何解决?
  • ¥15 为什么会突然npm err!啊
  • ¥15 java服务连接es读取列表数据,服务连接本地es获取数据时的速度很快,但是换成远端的es就会非常慢,这是为什么呢
  • ¥15 vxworks交叉编译gcc报错error: missing binary operator before token "("
  • ¥15 JSzip压缩文件时如何设置解压缩密码