I have a python script which runs perfectly on my work computer (1600 x 900 resolution). It is on this computer that I took all the screenshot images used by pyautogui.locateOnScreen. I tried to run this program on my home laptop with a different resolution (1340 x 640) and the script does not seem to find the image location. I am guessing that it is because of the different resolution. (I have copied the script folder from my work computer to the home computer, so the path to the image file is exactly the same). Is there anything I can change in my script so that pyautogui.locateOnScreen would identify the image on any computer resolution?
I'm the creator of PyAutoGUI. The problem you have isn't with the screen resolution, but the screen scaling. Your program will work fine on monitors at different resolutions. But at high resolutions, the text and buttons of your programs become too small and so Windows and macOS fix this with "screen scaling", which can increase the size of UI elements like text and buttons by 150% or 200%. If you have multiple monitors, each monitor can have it's own screen scaling setting; for example one monitor at 100% and another at 150%.
If you take a screenshot while a monitor is at, for example, 100% and then try to use it on a monitor that is scaled at 200%, the image won't match because the screenshot is literally half the width and length of what it would have been on the 200% monitor.
So far, there is no work around for this. Resizing the screenshot might not work because there could be subtle differences and the screenshot mechanism currently needs a pixel-perfect match. You just need to retake the screenshots on the monitor with the different screen scaling setting.
Running Pyautogui on a different computer with different resolution