【发布时间】:2021-08-02 08:52:55
【问题描述】:
我正在编写一个自动接受英雄联盟游戏的脚本,然后移动到聊天对话以呼叫车道。这对于 click_accept() 函数工作得很好,完美地打印出 x,y 坐标。但是click_chat_dialog() 的print(pos.x/2,pos.y/2) 行给了我以下错误:
AttributeError: 'NoneType' object has no attribute 'x'
这是我的代码:
import pyautogui, time, os, logging, sys, random, copy
def imPath(filename):
return os.path.join('images', filename)
def click_accept():
if pyautogui.locateOnScreen(imPath('accept_button.png'), confidence=0.8) != None:
pos = pyautogui.locateCenterOnScreen(imPath('accept_button.png'))
print(pos.x/2,pos.y/2)
pyautogui.moveTo(pos.x/2,pos.y/2)
time.sleep(0.5)
pyautogui.click(pos.x/2,pos.y/2)
def click_chat_dialog():
if pyautogui.locateOnScreen(imPath('chat_dialog.png'), confidence=0.6) != None:
pos = pyautogui.locateCenterOnScreen(imPath('chat_dialog.png'))
print(pos.x/2,pos.y/2)
pyautogui.moveTo(pos.x/2,pos.y/2)
time.sleep(0.5)
pyautogui.click(pos.x/2,pos.y/2)
while 1:
click_accept()
click_chat_dialog()
这是我正在使用的图片:
接受按钮 - https://i.imgur.com/1vW6cp3.png
聊天对话 - https://i.imgur.com/PwdXii3.png
【问题讨论】:
标签: python automation scripting pyautogui