1

I tried inserting a picture with format .jpg as a PhotoImage

But everytime i try running the program, it gives the following error:

couldn't recognize data in image file

But this never happens with an .png picture, which makes me wonder if .png is the only format acceptable in tkinter?

  • [This](https://stackoverflow.com/a/23905585/2570277) answer may help – Nick Sep 08 '22 at 10:56
  • 1
    If `tkinter` doesn't like your image file, you might want to try using the [PIL](https://pillow.readthedocs.io/en/stable/) library. This is the most popular library to use when trying to add pictures in `tkinter` – TheLizzard Sep 08 '22 at 10:58

1 Answers1

7

The docstring for PhotoImage says:

class PhotoImage(Image):
    """Widget which can display images in PGM, PPM, GIF, PNG format."""

So no, PNG is not the only acceptable format. PGM, PPM, GIF, and PNG are. JPEG is not.

AKX
  • 152,115
  • 15
  • 115
  • 172