我是python的新手,我知道我的代码确实很乱。我需要帮助,我希望下面的功能仅在识别到我设置的图像mc_ok_button.png
时才能运行,但是这有点令人困惑,因为我希望它与已经完成的循环结合在一起。如果我将代码放在循环中,它将不会运行下面的其余功能?
我的图像识别功能:
import pyautogui as pg
import pydirectinput as pd
import time
ax,ay = pg.locateCenterOnScreen('mc_ok_button.png',confidence=.6)
def function_when_restart():
print(ax,ay)
pd.click(ax,ay)
print('Waiting to return back to the server...')
time.sleep(8)
pd.moveTo(892,531)
print('finding server...')
pd.click()
print('connecting to the server...')
function_when_restart()
然后我希望仅当识别到function_when_restart()
图像并在mc_ok_button.png
运行时使project()
和fix_tool()
停止然后再返回function_when_restart()
和make project()
时才运行fix_tool()
功能:] >
from time import monotonic
from time import monotonic, sleep
start = monotonic()
while monotonic() - start < (60) : #Run for exactly 1 minute
# I want the image recognition to always run and if the image pops up I want
project()
sleep(5)
fix_tool()
我是python的新手,我知道我的代码确实很乱。我需要帮助,我希望下面的功能仅在我设置的图像被识别为mc_ok_button.png时才能运行,但是因为我想要...
下面可以帮忙吗?