gpt4 book ai didi

python - PyAutoGUIlocateOnScreen 方法中 minSearchTime 参数的目标是什么?

转载 作者:行者123 更新时间:2023-12-01 03:42:18 32 4
gpt4 key购买 nike

我看不出有什么区别

import pyautogui
pyautogui.locateOnScreen("anImage")

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

文档中没有关于 minSearchTime 的解释或引用。

最佳答案

当您想要等待一段时间才能显示图像时,这很有用。 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

关于python - PyAutoGUIlocateOnScreen 方法中 minSearchTime 参数的目标是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39370253/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com