本文介绍了Tkinter pyimage不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有很多类似的问题,但没有任何简单的我能够理解。我有以下代码:
I know there are lot of similar questions, but there aren't any simple enough that I am able to understand. I have the following code:
import Tkinter as tk
from PIL import Image, ImageTk
class MainWindow:
def __init__(self, master):
canvas = Canvas(master)
canvas.pack()
self.pimage = Image.open(filename)
self.cimage = ImageTk.PhotoImage(self.pimage)
self.image = canvas.create_image(0,0,image=self.cimage)
filename = full_filename
root = tk.Tk()
x = MainWindow(root)
mainloop()
我收到以下错误:
TclError: image "pyimage36" doesn't exist
我已经阅读了一些有关图像对象被垃圾清理的内容但我不太明白。
I've read some stuff about the image objects getting garbage cleaned but I don't quite understand it.
推荐答案
想出来。出于某种原因,当在调试器中运行时,如果任何先前的执行抛出错误,我得到pyimage不存在错误。但是,如果我重新启动调试器(或者以前没有执行过的脚本抛出错误),那么程序运行正常。
Figured it out. For some reason, while running in the debugger, if any previous executions had thrown errors I get the "pyimage doesn't exist" error. However, if I restart the debugger (or no previously executed scripts have thrown errors), then the program runs fine.
这篇关于Tkinter pyimage不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!