asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

Image File Not Found Exception... #852

Open m1zar opened 5 months ago

m1zar commented 5 months ago

Have a quite large project that uses the return value of 'None' to check for the presence of a particular icon/button etc, however on re-building the PC, I'm now getting this exception. Don't use, or even know, how to handle that. Should it be being thrown? Read that an exception is now thrown when an image is not found, seems odd way to do it to me. If the handler is generic how would I know where and what image it hasn't found. And to be honest, not finding the image is a valid return in my case (and probably others as well), so not sure why I would want an exception handler for that? Apologies, not the best python coder here, but in case I'm missing something, should it still return None and raise the exception for those that want to handle it (or does it HAVE to be handled?). Some example on this would really help on the documentation site, which only seems to say it now raises an exception. Have been using the module for quite some time, it's great and gets the job done, but would like to migrate the script to a better PC, requiring the re-install... if I have missed something obvious, please forgive me. Thanks for pyautogui, it's great.

m1zar commented 5 months ago

Reading the cheat sheet commit, it doesn't say if it still returns none or not. Or anything on how to handle it easily. Could a switch be added so the original functionality is still available. I've used that fact it returns None or the coordinates throughout. And don't like the idea of handling exceptions, sounds like a less reliable way to know an image is not on the screen. But hey, what do I know... not a lot to be honest! :-)

m1zar commented 5 months ago

I support I could PIP install an older version? Which is the last release to return 'none' for none found? I'll try that.

darkb0ts commented 5 months ago

However, it's also understandable that not finding an image could be a valid outcome in some cases, and you may not always want to handle it as an exceptional situation. In such cases, you can certainly handle the exception using a try-except block to gracefully handle the situation without interrupting the flow of your program.

bokai613 commented 4 months ago

I encountered the same question, you can try rollback PyScreeze to 0.1.29, 0.1.30 will occur this question

ash2262 commented 2 months ago

Yes I am also facing this issue. Can we somehow rollback to the previous version