When ever I try to use photoimage in tkinter I get this error
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2251, in _create
*(args + self._options(cnf, kw))))
TclError: image "pyimage6" doesn't exist
I have used this same method before and even on the same project, am i missing something here?
Here is the code.
self.repca = Canvas(self.rep)
self.repca.place(relx=0.00,rely=0.00,relheight=1.00,relwidth=1.00)
self.photo5 = PhotoImage(file='lib/maincanvas.gif')
self.repca.create_image(310,290, image =photo5)
Related
Every time, even though I have the source file, the same error message appears - 'Tcl error...could not recognize data in image file'. The problem also occurs with other images present in my disk drive.
Here is the code:
from tkinter import *
window=Tk()
window.geometry("420x420")
window.title('My first GUI programme')
source='D:\\Desktop\\op.jfif'
icon=PhotoImage(file=source)
window.iconphoto(True, icon)
window.mainloop()
Here goes the error:
PS D:\Documents\pythonProject> & "C:/Program Files (x86)/Python/python.exe" "d:/Documents/pythonProject/Learning python/Practice.py"
Traceback (most recent call last):
File "d:\Documents\pythonProject\Learning python\Practice.py", line 6, in <module>
icon=PhotoImage(file=source)
File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 4064, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 4009, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "D:\Desktop\op.jfif"
I don't know if there is any problem with my code or i need to change any settings. I would be thankful to you if you provide me any assistance.
I managed to do this by changing the file extension and file content of my image file to 'png' which worked in python.
Python Tkinter supports GIF, PGM, PPM, and PNG. So, try changing the extension of the file to one of them
i see your problem
i also have the same problem
I´m new to python and have problems with tkinker and the Images.
My error is:
Traceback (most recent call last):
File "D:/python/First Project/Weather app.py", line 12, in <module>
background_image = tk.PhotoImage(file='landscape.jpg')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 3498, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "landscape.jpg"
and the associated code is:
import tkinter as tk
root = tk.Tk()
background_image = tk.PhotoImage(file='D:\python\First Project\landscape.jpg')
background_label = tk.Label(root, image=background_image)
background_label.place(relwidth=1, relheight=1)
root.mainloop()
The ending of the file isn´t renamed and originally .jpg.
I also tried to edit it with
background_image = ImageTk.PhotoImage(Image.open('your.png'))
The PhotoImage method does not appear to support JPG files. I received the same error (couldn't recognise data in "image.jpg") when using a JPG file. When using a PNG file I did not receive any such errors.
Note that you cannot just change the file extension of a JPG file to turn it into a PNG file, because the data in PNG files is different from a JPG file. You will need to convert your JPG file to a PNG (or any other image file type supported by the PhotoImage method.)
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 :
When using Tkinter, error: TclError: image "pyimage8" doesn't exist
Python: Tkinter TclError: can't invoke "image" command
You can try with PhotoImage(file="path", master=root)
I am trying to display the image "picture.gif" in this code:
from graphics import *
import tkinter
win = GraphWin("Self Portrait", "1000", "500")
image = Image(Point(5,5), "picture.gif")
image.draw(win)
window.mainloop()
However, I keep getting this error:
Traceback (most recent call last):
File "/Users/jstorrke/Desktop/Python/graphicsProject.py", line 6, in <module>
image = Image(Point(5,5), "picture.gif")
File "/Users/jstorrke/Desktop/Python/graphics.py", line 827, in __init__
self.img = tk.PhotoImage(file=pixmap[0], master=_root)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3394, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3350, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "picture.gif"
The graphics module provides very minimal support for displaying images. Try putting the image on the same folder as where graphics library is and see if it helps.
Please look at this document for more information on graphics module. http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf
_tkinter.TclError: couldn't recognize data in image file "picture.gif"
I looked at dozens of examples this error message and the cause seems to fall into two categories:
1) The file wasn't a supported type (e.g. *.jpg, *.png, *.tif) which was obvious from the extension.
2) The file used was mislabeld as a *.gif when it wasn't. (More common than I would expect.) On Unix systems you may be able to use the file command to verify your GIF:
> file p7Q6O.gif
p7Q6O.gif: GIF image data, version 89a, 520 x 416
>
An actual failure of a valid GIF file occurs if it's an animated GIF which are not supported. However, this can be a silent failure -- no error message and no image displayed.
I am trying to render an image in tkinter. I have seen many scripts on stack overflow on how to make an image, but when I try that it says that my picture does not exist. Is there a certain place where I have to store my image? My python script is saved to the desktop, but I know that python may not search there. Where do I put the image that I want to show in my program? Thanks in advance!
Edit: Here is requested code:
canvas = Canvas(app, width=300, height=250).pack()
picture = PhotoImage(file='image.gif') #image located in desktop
canvas.create_image(0,0, image = picture
Here is the error:
Traceback (most recent call last):
File "/Users/theroeloffs/Downloads/myprogram.py", line 87, in <module>
piper_pic=PhotoImage(file = 'image.gif')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 3306, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 3262, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "image.gif": no such file or directory
sorry for some reason this website wouldn't let me make that code
P.S. I have a mac
Just put it in the same file as your script.
Hope that helps!
You can use absolute path to it:
picture = PhotoImage(file='/Users/theroeloffs/Desktop/image.gif')
Or the better version is, to copy your image to this location:
/Users/theroeloffs/Downloads/image.gif
(where your script is) and than you can use the file name only:
picture = PhotoImage(file='image.gif')