[英]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.