我有一堆链接和标签list
来查看我想要制作具有下一个、上一个功能的图像查看器的那些。我的各个图像的链接和标签位于list
. 到目前为止,我已经尝试过:
urls=[url,url1,url2,url3]
labels=["label 1","label 2","label 3","label 4"]
images=[]
for ur in urls:
raw_data = urllib.request.urlopen(ur).read()
im = Image.open(io.BytesIO(raw_data))
image = ImageTk.PhotoImage(im)
images.append(image)
现在我已经准备好图像images
,现在我想在图像查看器中显示它,但在图像查看器中只有最后一张图像可见。
Label(root).grid(row=1,column=1)
for i in range(len(images)):
image_label=Label(root,image=images[i])
image_label.grid(row=1,column=2)
name=Label(root,text=labels[i])
name.grid(row=2,column=2)
def left():
image_label=Label(root,image=images[i-1])
image_label.grid(row=1,column=2)
def right():
image_label=Label(root,image=images[i+1])
image_label.grid(row=1,column=2)
left_button=Button(root,text="Left",command=left)
left_button.grid(row=2,column=1)
right_button=Button(root,text="Right",command=right)
right_button.grid(row=2,column=3)
右键不工作,左键工作,但只有一次。当我第二次单击左键时,没有任何效果。
单击右键时出错:
line 45, in right
image_label=Label(root,image=images[i+1])
IndexError: list index out of range