1

我看不出有什么区别

import pyautogui
pyautogui.locateOnScreen("anImage")

import pyautogui
pyautogui.locateOnScreen("anImage", minSearchTime=10)

并且文档中没有关于minSearchTime.

4

1 回答 1

2

当您想等待一段时间以显示图像时,它很有用。PyAutoGUI 将继续截屏并搜索图像,直到 minSearchTime 结束。我从源代码中得到了这个:

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

于 2018-12-05T22:06:44.703 回答