我希望today变量是一周中x,y坐标的任意一天。使用datetime.weekday会返回一个0,我不能将它赋给坐标。我可以使用7个if语句,但这似乎过多了。有没有更好的方法?
MON = (340, 431)
TUE = (529, 432)
WED = (721, 436)
THUR = (912, 436)
FRI = (1107, 435)
SAT = (1293, 436)
SUN = (1484, 434)
dow = dt.today().weekday() #get day of week
if dow == 0:
today = MON
if dow == 1:
today = TUE
pyautogui.click(today) #if today is monday the x,y coordinates of (340, 431) will be here
time.sleep(1)发布于 2021-09-06 18:33:01
使用坐标创建一个数组,并使用dow作为其索引:
coords = [(340, 431),(529, 432),(721, 436),(912, 436),(1107, 435),(1293, 436),(1484, 434)]
dow = dt.today().weekday()
today = coords[dow] # note that the first day of the week may not be monday
pyautogui.click(today)https://stackoverflow.com/questions/69078918
复制相似问题