Label.image显示AttributeError:'NoneType'对象没有属性'image'

问题描述 投票:0回答:1

我一直在尝试使用以下代码在标签上显示图像:

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

最后一行没有给出属性错误,当我删除最后一行时,图像消失了。

python label
1个回答
0
投票

尝试将最后两行更改为:

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

© www.soinside.com 2019 - 2024. All rights reserved.