0

I'm using pyautogui for my project, here is a snippets of the code

# Other function inside while loop
 time.sleep(8)
 Click('join_audio.png')
 break 

Click() is a class i made that locate the image and click it, but i want the action to start when that image has appeared on the screen instead of waiting for 8 second which is not that effective. Is there a way to do this in python?

TheNoobProgrammer
  • 1,013
  • 4
  • 10
  • 21
  • You could programmatically check for the image's existence in a loop, with small sleeps in the loop. Without more background info through it's impossible to really help you. – Random Davis Oct 16 '20 at 16:13
  • the while loop only consist of pyautogui clicking a specific button with time.sleep() between each action. My project is internet-based, that's why i want to use image validation rather than time.sleep() – TheNoobProgrammer Oct 16 '20 at 16:23
  • What do you mean by Image Validation in this case? – Random Davis Oct 16 '20 at 16:56
  • I want to detect if the image exist on the screen, in this case i want join_audio.png to exist on the screen then click it, else it wait until it the image exist. – TheNoobProgrammer Oct 16 '20 at 17:00
  • Does [this](https://stackoverflow.com/questions/27343997/using-pil-python-image-library-to-detect-image-on-screen) help? – Random Davis Oct 16 '20 at 17:39

1 Answers1

0

Instead of using time.sleep, you can use this code:

from pyautogui import *
hotkey("alt", "tab")
Click("join_audio.png")
break

But you have to make sure that if you press Alt-Tab, the image will be there on the screen. If you do that, then this will work for you

EasyWay Coder
  • 331
  • 1
  • 7