简体   繁体   中英

Pyautogui declare a variable

In the below statement:-

pyautogui.confirm('Choose one.', buttons=['Print A', 'Print B', 'Print C'])

In there I would like to add a variable for each button, but I don't know exactly how to do it.

I'm unsure what you mean by "add a variable for each button" but I'd venture to guess you want to correlate a variable or function to a button. You could use a dict for this:

a = "You choose A"
b = "You choose B"
c = "You choose C"
choices = {'Print A': a, 'Print B': b, 'Print C': c}
answer = pyautogui.confirm('Choose one.', buttons=list(choices))
#then either print the variable
print(choices[answer])
#or show it in an alert
pyautogui.alert(text=choices[answer], button='OK')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM