Pyautogui 声明一个变量
Pyautogui declare a variable
在下面的语句中:-
pyautogui.confirm('Choose one.', buttons=['Print A', 'Print B', 'Print C'])
在那里我想为每个按钮添加一个变量,但我不知道具体怎么做。
我不确定您所说的 "add a variable for each button" 是什么意思,但我敢猜测您想将变量或函数与按钮相关联。您可以为此使用字典:
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')
在下面的语句中:-
pyautogui.confirm('Choose one.', buttons=['Print A', 'Print B', 'Print C'])
在那里我想为每个按钮添加一个变量,但我不知道具体怎么做。
我不确定您所说的 "add a variable for each button" 是什么意思,但我敢猜测您想将变量或函数与按钮相关联。您可以为此使用字典:
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')