我一直在尝试使用以下代码在标签上显示图像:
for i in range (0, 10):
img = Image.open("Toy Story.PNG")
img.load()
img = img.resize((100, 100), Image.ANTIALIAS)
img_title = ImageTk.PhotoImage(img)
print(img_title)
myLabel_image = Label(tab_recommend, height = 90, width = 90, image = img_title).place(x=108,y=200)
myLabel_image.image = img_title #For creating reference
最后一行没有给出属性错误,当我删除最后一行时,图像消失了。
尝试将最后两行更改为:
myLabel_image = Label(tab_recommend, height = 90, width = 90, image = img_title)
myLabel_image.place(x=108,y=200)
myLabel_image.image = img_title
[place
方法不返回Label,而是就地对其进行修改,返回None
。