3

PhotoImage for images in PGM, PPM, GIF and PNG formats. The latter is supported starting with Tk 8.6.

Information about my environment,

  • WIN10
  • Python 3.6.0
  • tkinter.TkVersion 8.6
  • tkinter.Tcl().eval('info patchlevel') 8.6.6

I got some PNG files failed in following script

from tkinter import *

root = Tk()

bg = PhotoImage(file='d:/Fandom.png')    # Failed here
bg_label = Label(root, image=bg)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)

root.mainloop()

Different PNG files can be downloaded from

File header for both files are the same 89 50 4E 47 0D 0A 1A 0A for PNG file. Both files can be shown without any problem under lot of softwares, lik windows File manager, ACDSEE, Paint, ...

Failure information for different PNG files

# Fandom.png
Traceback (most recent call last):
  File "<module1>", line 5, in <module>
  File "C:\Software\Python\lib\tkinter\__init__.py", line 3539, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Software\Python\lib\tkinter\__init__.py", line 3495, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "orNT"

# duck.png
Traceback (most recent call last):
  File "<module1>", line 5, in <module>
  File "C:\Software\Python\lib\tkinter\__init__.py", line 3539, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Software\Python\lib\tkinter\__init__.py", line 3495, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: encountered an unsupported criticial chunk type "eXIf"

Library Pillow (PIL) may help to work, but not the question here.

My questions are

  • Do python 3.6.x with tkinter 8.6 support all PNG files ?
  • If not, what format or version of PNG file get support ?
Jason Yang
  • 11,284
  • 2
  • 9
  • 23
  • Both images work fine in my Python 3.9.2 with tkinter 8.6.9 in Windows 10. – acw1668 Apr 06 '21 at 03:34
  • I knew it is OK on Python 3.9.x, but My question is for python 3.6.x in WIN 10. – Jason Yang Apr 06 '21 at 04:26
  • Came here looking for SAME question... "does 8.6.6 not support some PNG files?"... It would seem that it has trouble with some such as - https://www.python.org/static/community_logos/python-logo-master-v3-TM.png. Works fine on Python 3.7, but not 3.6. Nice find Jason! (will document in new docs) – Mike from PSG Nov 30 '22 at 13:07
  • Does this link help? https://www.python.org/downloads/release/python-363/ – toyota Supra May 28 '23 at 09:27
  • I knew some different version Python may work, but its not my question here. Anyway, still thank you for your reply. – Jason Yang May 28 '23 at 10:00

0 Answers0