Python 3.6.3 pyautogui.locateOnScreen not working

十年热恋 提交于 2020-01-16 09:43:28

问题


I have a "find.png" (attached) The pyautogui.locateOnScreen is returning None, even after 20 screenshots!!!! Using interpreter (code attached) Note: 1) the image having the line, "import pyautogui as auto", is "find.png" 2)I have "find.png" in the same directory, it is founded( checked with PIL- Image)


回答1:


After struggling with this forever also, finally figured out that you either use command line or print screen button with the windows key to take the screenshot. Using the snipping tool does not work so try:

image = pyautogui.screenshot()
image.save('testing.png')

Go and crop testing.png as small as possible so that locateOnScreen works faster. Then go back to the terminal and type:

pyautogui.locateOnScreen('testing.png')



回答2:


Try this:

location = pyautogui.locateOnScreen('testing.png', confidence =.8)



回答3:


None simply means that PyAutoGui was unable to find your image on the screen, do remember the window is active where find.png was sampled from. If this doesn't work out then I believe the resolutions(from when you took the sample and the monitor used by you) are different. Let us know if you face any problem.



来源:https://stackoverflow.com/questions/48709009/python-3-6-3-pyautogui-locateonscreen-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!