The code works when it sees the image, however it gives up (an error that says "cannot unpack non-iterable NoneType object") instead of retrying once the image it's looking is affected by certain circumstance like moving a window that blocks the code's view.
This is the code
import pyautogui
while True:
x, y = pyautogui.locateCenterOnScreen('icon.png', confidence=0.8)
print(x, y)