When using Tkinter, error: TclError: image "pyimage8" doesn't exist When using Tkinter, error: TclError: image "pyimage8" doesn't exist tkinter tkinter

When using Tkinter, error: TclError: image "pyimage8" doesn't exist


I found that my script would run once and then give me an error on subsequent runs. If I restarted the console, it would run again. I solved the problem by using the following code in the beginning of my script:

import sysif "Tkinter" not in sys.modules:    from Tkinter import *

It works every time now.


If you import Tkinter as tk you should use the alias tk when calling tk, eg. root = tk.Tk(). Otherwise Python will not find Tk.

You don't need to import PIL for this.

You can not create a Photoimage before you create Tk.

Try this:

import Tkinter as tkroot = tk.Tk()root.title("Welcome to the Pit!")root.geometry("1100x700")homescreenImage = tk.PhotoImage(file="Homescreen.gif") homescreenFrame = tk.Frame(root, width=1100, height = 700,)homescreenFrame.pack()homescreenLabel = tk.Label(homescreenFrame, image=homescreenImage)homescreenLabel.pack()root.mainloop()

Be kind and paste the whole error message in your question also.


Following could be the errors:

1) Give the whole path to the file name eg: "/home/user/Homescreen.gif"

2) If you are using windows and the above doesn't work: use "\\C:\\home\\Homescreen.gif" (this is because, windows gets confused)

3) If that also, doesn't work, ensure that the directory of your python program is the same as that of the image.

4) Also, create the photoimage only after you have created the root window.

5) 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.

6) Also, don't import PIL, it's not required.

Try all the above, if it doesn't work let me know.Hope this helps.