Python Forum

Full Version: how to avoid reapiting lines with locateonscreen
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello !

there is any solution to avoid repetition lines in python when i search for many images on screen with Pyautogui.locateOnScreen()
because i search for six images and this is my code :

import pyautogui
import time
pyautogui.locateOnScreen('img1.png',confidence=0.7)
pyautogui.locateOnScreen('img2.png',confidence=0.7)
pyautogui.locateOnScreen('img3.png',confidence=0.7)
pyautogui.locateOnScreen('img4.png',confidence=0.7)
pyautogui.locateOnScreen('img5.png',confidence=0.7)
pyautogui.locateOnScreen('img6.png',confidence=0.7)
I have no experience with pyautogui but shouldn't simple loop suffice? Something like:

for i in range(1, 7):
    pyautogui.locateOnScreen(f'img{i}.png',confidence=0.7)
(Feb-04-2021, 12:59 PM)perfringo Wrote: [ -> ]I have no experience with pyautogui but shouldn't simple loop suffice? Something like:

for i in range(1, 7):
    pyautogui.locateOnScreen(f'img{i}.png',confidence=0.7)

i tried it but its didn't work
(Feb-07-2021, 09:17 PM)rachidel07 Wrote: [ -> ]i tried it but its didn't work
didn't work is not very descriptive. probably you did something wrong. show the full traceback