有人知道如何使python点击方块记忆游戏?例:我要记住这个谜题(红色方块是随机的):https://i.stack.imgur.com/K5eFl.png
我如何使python在它们消失后单击红色方块?
我想知道屏幕上是否有一个红色的方块。
from pyautogui import *
import pyautogui
import time
from playsound import playsound
while 0:
if pyautogui.locateOnScreen('model_square.png', confidence=1) != None:
print("There is a red square")
playsound('audio.mp3')
time.sleep(1)
else:
print("No squares")
time.sleep(1)
如果在屏幕上找到给定图像,pyautogui.locateOnScreen('model_square.png', confidence=1)
将返回(x,y)值。
pyautogui.click(x,y)
将点击给定的x,y。
我们可以简单地声明一个变量来存储屏幕上红色方块的x,y值然后在pyautogui.click(variable)
中传递变量来点击红色方块的x,y坐标
while 0:
#This variable will return x,y of the image found on the screen
red_square = pyautogui.locateOnScreen('model_square.png', confidence=1)
if red_square != None:
#click the x,y where the image is found on the screen
pyautogui.click(red_square)