ylipaa
ylipaa

Reputation: 21

pyautogui Python 3.6 interact with ok button

I want to use the pyautogui.alert function and i want a special action to be done after the user clicks the OK button. How can i interact with this button?

pyautogui.alert (text = '', title = '', button = 'OK')

Upvotes: 2

Views: 1539

Answers (2)

Aggelos Nikolaras
Aggelos Nikolaras

Reputation: 93

Or you can do this:

# display the alert
alert = pyautogui.alert(text = '', title = '', button = 'OK')
# check to see if "OK" was pressed
if alert.upper() == "OK":
    # do something

Upvotes: 2

Hamza Khurshid
Hamza Khurshid

Reputation: 825

According to the documentation of pyAutoGUI,

Alert() Displays a simple message box with text and a single button. Returns the text of the button clicked on.

If you want to trigger some action when user clicks the OK button, you can store result of button press in a variable and check it with a condition.

pressed=pyautogui.alert(text='', title='', button='OK')
if(pressed=='OK'):
    #DO SOMETHING

Upvotes: 0

Related Questions