[英]How to make python click squares on memory game
someone know how to make python click squares on memory game?有人知道如何在 memory 游戏上制作 python 点击方块吗? EX: I have this puzzle to memorize(The red squares are random): https://i.imgur.com/IP54Qef.png
例:我要记住这个谜题(红色方块是随机的): https://i.imgur.com/IP54Qef.png
How do i make python to click red squares after they dissapear?我如何让 python 在它们消失后点击红色方块?
I managed to find if there is a red square on the screen.我设法找到屏幕上是否有红色方块。
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)
will return (x,y) values of the given image if found on the screen. pyautogui.locateOnScreen('model_square.png', confidence=1)
如果在屏幕上找到,将返回给定图像的 (x,y) 值。
pyautogui.click(x,y)
will click on the given x,y. pyautogui.click(x,y)
将点击给定的 x,y。
So to code what you want to do we can simply declare a variable that will store x,y of the red squares found on the screen and then pass the variable in pyautogui.click(variable)
to click the x,y coordinates of the red squares因此,要编写您想做的事情,我们可以简单地声明一个变量,该变量将存储屏幕上找到的红色方块的 x、y,然后将变量传递给
pyautogui.click(variable)
以单击红色的 x、y 坐标正方形
So your code for that would be:所以你的代码是:
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.