我正在使用PIL加载一个jpg文件并将其显示在label小部件中。首先,我从python得到了“解码错误”,并在堆栈溢出上找到了这篇文章- How can I install PIL on mac os x 10.7.2 Lion -它解决了解码错误。但是,标签不显示任何图像,只显示一个白色区域。这是加载图片的代码-
script, file = argv
self.orgimg = Image.open(file)
#Original Image
img = ImageTk.PhotoImage(self.orgimg)
Label(self.root, image=img).grid(row=0,column=0,padx=5,pady=5)发布于 2013-04-15 16:08:40
我有一种感觉,那张图片被垃圾回收了。看看这个:http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm
如果将图像存储在局部变量中,则在函数返回时将对其进行垃圾回收。
发布于 2012-11-06 23:18:14
https://stackoverflow.com/questions/13253617
复制相似问题