Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with Pyautogui
#1
Sad 
first of all i'm a bigginner and i have a problem with Pyautogui .

i create a simple code to find the software logo on desktop then type 'I found it ' ,and if i hide the logo the cod type 'I am unable to found it,the code works good.
but when i add another action ,which is i want the mouse move to the position of the logo . its works good ,but when i hide the logo the mouse still move to the postion ,and still type i found it , but normally the code should show me I am unable to found it.
please heelp me with an correct cod.


my code is:
import pyautogui
import time

location = pyautogui.locateOnScreen('image.png', confidence = 0.6)

while 1:

    if location:

        print("I found it ")
        time.sleep(2)
        print(pyautogui.moveTo(location))

    else:

        print("I am unable to found it")
nilamo write Jan-27-2021, 05:44 PM:
Added code tags for you.
Reply
#2
(Jan-27-2021, 04:25 PM)rachidel07 Wrote:
location = pyautogui.locateOnScreen('image.png', confidence = 0.6)
while 1:
    if location:

You check for the file's location one time, when the script starts. If you hide it after starting the script, it won't "forget" where it is, because you never check for it again. If you want to continuously watch for the object, you need to continuously look for the object. Like this:
while True:
    location = pyautogui.locateOnScreen('image.png', confidence = 0.6)
    if location:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyautogui, İmagesearch, Moving target Beyazx 0 550 Jun-27-2023, 08:47 PM
Last Post: Beyazx
  PyautoGUI- How to use If - Else with pyautogui.locateCenterOnScreen Tiel 3 8,127 Jun-27-2022, 02:00 PM
Last Post: DeaD_EyE
  pyautogui.locateOnScreen producing error dude8074 6 3,731 Apr-17-2022, 05:05 PM
Last Post: bowlofred
  how to take a screnshot by Pyautogui automatically and randomly rachidel07 0 3,482 Feb-03-2021, 01:16 PM
Last Post: rachidel07
  pyautogui with a display emulator? gumby4231 0 2,550 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  pyautogui.screenshot region is not working alexlu 6 6,384 Jun-04-2020, 10:46 AM
Last Post: alexlu
  loop in pyautogui (python automation GUI application) pyprogrammer 0 4,719 Feb-12-2020, 02:52 PM
Last Post: pyprogrammer
  Doesn't work function pyautogui.typewrite() aliyevmiras 1 4,755 Dec-22-2019, 11:35 AM
Last Post: aliyevmiras
  pyautogui while loop Bmart6969 0 6,526 Oct-03-2019, 03:32 PM
Last Post: Bmart6969
  Can't run pyautogui on Mohave veromi22 4 2,887 Sep-30-2019, 12:41 AM
Last Post: veromi22

Forum Jump:

User Panel Messages

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