我想做一个简单的机器人来学习pyautogui功能,但一开始我就遇到了一个问题。
import pyautogui
import keyboard
import time
def locate(image):
pyautogui.locateOnScreen(image, grayscale = True, confidence = 0.9)
x = pyautogui.locateOnScreen('test2.png', grayscale = True, confidence = 0.9)
y = locate('test2.png')
while keyboard.is_pressed('q') == False: # I put locateOnScreen \/ as a control test
print(x, y, locate('test2.png'), pyautogui.locateOnScreen('test2.png', grayscale = True, confidence = 0.9))
time.sleep(1)
当执行的程序返回时:
None None None Box(left=452, top=767, width=702, height=88)
因此,x, y and locate()
函数似乎无法正常运行,即使它们由pyautogui.locateOnScreen
组成并且具有相同的值。