Python Forum
how to avoid reapiting lines with locateonscreen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to avoid reapiting lines with locateonscreen
#1
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)
Reply
#2
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)
buran, Serafim, nilamo like this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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
Reply
#4
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyautogui.locateOnScreen producing error dude8074 6 3,859 Apr-17-2022, 05:05 PM
Last Post: bowlofred
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,879 Aug-10-2020, 11:01 PM
Last Post: medatib531

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020