I want to simply display a logo or image in my GUI. I tried different techniques as posted on the internet, however all seems to give me an error as TclError: image "pyimage27" doesn't exist. I have checked the file is correct(png file) and the path too. I still cant display the image. Below is my simple code:
import tkinter as tk
root = tk.Tk()
def show_image():
img_label = tk.Label(root)
img_label.image = tk.PhotoImage(file="logo.png")
img_label['image'] = img_label.image
img_label.pack()
show_image()
root.mainloop()
Error that i get
File "C:\Users\bb\Documents
\line.py", line 54, in <module>
alien()
File "C:\Users\bb\Documents
\test.py\line.py", line 26, in __init__
self.alien2 = self.canvas.create_image((100,100),image=CardVar,anchor=CENTER)
File "C:\Users\bb\Anaconda3\lib\tkinter\__init__.py", line 2489, in create_image
return self._create('image', args, kw)
File "C:\Users\bb\Anaconda3\lib\tkinter\__init__.py", line 2480, in _create
*(args + self._options(cnf, kw))))
TclError: image "pyimage30" doesn't exist
Thank you
Many similar answers are available but that did not help :
Tk(), this is one of the numerous problems that can result from that. - jasonharpercreate_image()but your code does not have such statement. - acw1668Tk()once. To avoid that depends only exactly what you're trying to do (which we can't tell from the sample code in your question). - martineauToplevel()to create additional windows.Tk()does much more than create a window - it creates the entire Tcl/Tk environment that implements the GUI, the window is just an unavoidable side-effect. If you call it more than once, you can have situations such as an image existing in one of the environments, and a widget wanting to use that image existing in another environment. - jasonharper