import pyautogui as p
p1=p.confirm(
text='youare',
title='prank',
buttons=['cat','dog','other'])
if p1=='dog':
p.alert('hello bow bow')
elif p1=='cat':
p.alert('hello meow meow')
else:
#what I should give in else statement such that the p1 statement should be repeated till I click on dog and cat buttons.#
How to repeat p1 statement again and again till I click on dog button or cat button?
CodePudding user response:
import pyautogui as p
while True:
p1 = p.confirm(
text='This is Text',
title='This is Title',
buttons=['cat', 'dog', 'other'])
if p1 == 'dog' or p1 == 'cat':
break
else:
continue
CodePudding user response:
You should verify the value of p1 and prompting it as long as it's not "dog" or "cat" in a while
loop.
import pyautogui as p
p1 = p.confirm(text='youare', title='prank',
buttons=['cat', 'dog', 'other'])
while p1 not in ['dog', 'cat']:
p1 = p.confirm(text='youare', title='prank',
buttons=['cat', 'dog', 'other'])
# Once the code arrives there, you are certain p1 is either cat or dog
if p1 == 'dog':
p.alert('Hello bow bow')
else:
p.alert('Hello meow meow')