我正在尝试更改 for 循环的索引,具体取决于用户是否要转到上一个图像(索引 = 索引 - 1)以及是否要转到下一个图像(索引 = 索引 + 1)但是,索引没有改变外循环(在 if 语句之外)。flag = Falsewhile flag == False: for i in range(len(all_image)): image = all_image[i] print(i) userchoice = easygui.buttonbox(msg, image = image, choices=choices) if userchoice == 'Next': i = i+1 elif userchoice == 'Previous': i = i-1 elif userchoice == 'cancel': print('test') flag = True break 提前致谢。
1 回答

慕斯709654
TA贡献1840条经验 获得超5个赞
不知道为什么存在 for 循环,我很想将它的结构更像这样:
flag = False
idx = 0 #idx is where we are in the image list, and it gets modified by use choices in the while loop.
while flag == False:
image = all_image[idx]
print(idx)
userchoice = easygui.buttonbox(msg, image = image, choices=choices)
if userchoice == 'Next':
idx += 1
elif userchoice == 'Previous':
idx -= 1
elif userchoice == 'cancel':
print('test')
flag = True
break
添加回答
举报
0/150
提交
取消