use*_*843 6 python image tkinter python-imaging-library
我知道有很多类似的问题,但没有任何简单的我能够理解.我有以下代码:
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()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
TclError: image "pyimage36" doesn't exist
Run Code Online (Sandbox Code Playgroud)
我已经阅读了一些关于图像对象被垃圾清理的东西,但我不太明白.
use*_*843 11
弄清楚了.出于某种原因,在调试器中运行时,如果任何先前的执行抛出错误,我会得到"pyimage不存在"错误.但是,如果我重新启动调试器(或者以前没有执行的脚本抛出错误),那么程序运行正常.
| 归档时间: |
|
| 查看次数: |
11541 次 |
| 最近记录: |