PyAutoGUI locateOnScreen方法中minSearchTime参数的目标是什么?

2024-10-03 02:35:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我看不出两者有什么区别

import pyautogui
pyautogui.locateOnScreen("anImage")

以及

^{pr2}$

文档中没有关于minSearchTime的解释或参考。在


Tags: 文档import区别pyautoguipr2locateonscreenanimageminsearchtime
1条回答
网友
1楼 · 发布于 2024-10-03 02:35:49

当您希望等待一段时间后图像出现时,它非常有用。PyAutoGUI将继续制作屏幕截图并搜索图像,直到分钟搜索时间过去。 我从源代码中得到:

def locateOnScreen(image, minSearchTime=0, **kwargs): """minSearchTime - amount of time in seconds to repeat taking screenshots and trying to locate a match. The default of 0 performs a single search. """ start = time.time() while True: try: screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here. retVal = locate(image, screenshotIm, **kwargs) try: screenshotIm.fp.close() except AttributeError: # Screenshots on Windows won't have an fp since they came from # ImageGrab, not a file. Screenshots on Linux will have fp set # to None since the file has been unlinked pass if retVal or time.time() - start > minSearchTime: return retVal except ImageNotFoundException: if time.time() - start > minSearchTime: raise

和13;
和13;

相关问题 更多 >