Tikinter pyimage does not exist

I know that there are many similar questions, but there are no simple enough for me 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()

and I get the following error:

TclError: image "pyimage36" doesn't exist

I read something about image objects that clean up garbage, but I don't quite understand.

+6
source share
2 answers

Figured it out. For some reason, while working in the debugger, if any previous quotation marks throw errors, I get the error "pyimage does not exist". However, if I restart the debugger (or previously not executed scripts cause errors), the program works fine.

+11
source

spyder 3.3.6. .png "Tinker pyimage error" - . .

0

Source: https://habr.com/ru/post/1544996/


All Articles