8
votes

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()

and I get the following error:

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.

3
Show full error message - there is more information. Is "pyimage36" a filename or what ? - furas
I have been having this problem too. I seem to only have this issue when I am using Spyder. I get the error when using Spyder both in windows and in Linux (Raspbian). When I use Idle on the Pi or Pycharm on windows I don't get this behavior. - BRM

3 Answers

15
votes

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.

1
votes

I had the same error message when using spyder 3.3.6 the only way i could get the .png file to load and display after getting the 'Tinker pyimage error ' was to go to the Console and restart the kernel. After that i worked fine.

-2
votes

From programmersought

image “pyimage1” doesn’t exist Because there can only be one root window in a program, that is, only one Tk() can exist, other windows can only exist in the form of a top-level window (Toplevel()).

Original code

import tkinter as tk
window = tk.TK()

Revised code

import tkinter as tk
window = tk.Toplevel()

Keep other code unchanged

https://www.programmersought.com/article/87961175215/