SovietStormSam
SovietStormSam

Reputation: 123

Why has my pyautogui Code stopped locating buttons on the screen?

My program was working fine, locating the area the button was in using pyautogui.locateOnScreen and then locating the center of the button using pyautogui.locateCenterOnScreen obviously with a file path to the correct image.

Now, though, running it returns the value of none for both the center and location.

I have uninstalled pyautogui and reinstalled it and it has not fixed it.

I am only focusing on the RecordMP3 bit of code

Here is my code

import pyautogui, time
def RecordMP3():
    time.sleep(5)
    RecordMP3 = pyautogui.locateOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG")
    print(RecordMP3)
    CenterRecordMP3 = pyautogui.locateCenterOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG",region = (RecordMP3))
    print(CenterRecordMP3)  
    pyautogui.click(CenterRecordMP3)

def SaveButton():
    while True:
        counter = 0
        SaveButton = pyautogui.locateOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG")
        print("Location",SaveButton)
        SaveButtonCenter = pyautogui.locateCenterOnScreen("D:/Programming/Python/AutoGUI/Images/SaveButton.PNG", region = (SaveButton))
        print("Center",SaveButtonCenter,)
        pyautogui.click(SaveButtonCenter)
        time.sleep=(2)
        counter +=1
        if counter < 10:
            continue
        else:
            break

#print("it worked!!")  
RecordMP3()

This is the screen I search:

Screen I want to search for button

And this is the button I'm trying to find:

The record button I want to find

Upvotes: 1

Views: 1176

Answers (2)

Valter
Valter

Reputation: 11

Though my suggestion is also a little late I have run into this issue as well like many other people.

I have solved this by compyling the .py into .exe with auto-py-to-exe.

Hope that works for you.

Upvotes: 1

Kaczuszki
Kaczuszki

Reputation: 1

Though my suggestion is a little late I have run into this issue as well. I have solved this by taking another screen shot of the image I am looking for. As a friendly reminder if the image is not pixel perfect pyautogui wont find it.

Hope you found a solution!

Upvotes: 0

Related Questions