0
import tkinter
from tkinter import *
from PIL import Image

root = tkinter.Tk()
photo = tkinter.PhotoImage(file="two.png")
cv = tkinter.Canvas()  
cv.pack(side='top', fill='both', expand='yes')  
cv.create_image(0, 0, image=photo, anchor='nw')  
root.mainloop()

The code displays png file but when I replace png file with a jpg file, it fails to displays it giving following error,

Traceback (most recent call last):
  File "C:/Users/DB/AppData/Local/Programs/Python/Python35/Python Code/img_disp.py", line 6, in <module>
    photo = tkinter.PhotoImage(file="two1.jpg")
  File "C:\Users\DB\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 3402, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\DB\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 3358, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "two1.jpg"

I want to display jpg image with a specific width and height in UI created using tkinter. Please guide...

j_4321
  • 15,431
  • 3
  • 34
  • 61
Vrajesh Doshi
  • 744
  • 2
  • 8
  • 27
  • 1
    Have you searched for the error "couldn't recognize data in image file" and "jpg"? Please do a little research before posting such a basic question – Bryan Oakley Dec 02 '17 at 17:29
  • Possible duplicate of [How do I insert a JPEG image into a python Tkinter window?](https://stackoverflow.com/questions/23901168/how-do-i-insert-a-jpeg-image-into-a-python-tkinter-window) – j_4321 Dec 04 '17 at 08:55

0 Answers0