PyAutoGUI for loop unable to loop through

Viewed 17

I'm trying to loop through a list of image for

pyautogui.locateOnScreen()

Here is my approach

vnc2 = r"D:\directory\of\image\vnc_2.png"
vnc3 = r"D:\directory\of\image\vnc_3.png"
vnc4 = r"D:\directory\of\image\vnc_4.png"
vnc_list = [vnc2 , vnc3, vnc4]

        for step in vnc_list :
            x,y = pa.locateOnScreen(step)
            pa.click(x,y)
            time.sleep(2)

The trace back as below

Traceback (most recent call last):
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "d:\Self learn\python automation\MMVNA_auto.py", line 101, in automation
    x,y = pa.locateCenterOnScreen(step)
TypeError: cannot unpack non-iterable NoneType object

Is it not right to loop through ? or did i miss out something important ?


Updates

Beginners mistake Here is my code before the for loop

        x,y = pa.locateCenterOnScreen(vnc1)
        pa.click(x,y) 
        pa.typewrite("192.168.7.2")
        pa.press("enter")
        for step in vnc_list :
            x,y = pa.locateCenterOnScreen(step)
            pa.click(x,y)
            time.sleep(2)

i left out the time.sleep(5) after pa.press("enter")

0 Answers
Related