[英]How to make python click squares on memory game
有人知道如何在 memory 游戏上制作 python 点击方块吗? 例:我要记住这个谜题(红色方块是随机的): https://i.imgur.com/IP54Qef.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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.