0

I am not sure how to get PNGs show up Python. When I tried the following code, all it gave was an error, even when I got the PNG image on the same folder as the Python program is.

from tkinter import *
import tkinter as tk

root = tk.Tk()
root.geometry("960x600")

an_image=PhotoImage(file="test.png")

root.mainloop()

And I got the error shown up as exactly the following:

Traceback (most recent call last):
File "E:/school stuff/2018/IT Advanced/python projects/random testing/buttonimage.py", line 7, in <module>
an_image=PhotoImage(file="test.png")
File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line 3539, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line 3495, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "test.png"

Is there some way to make the PNG show up on the program GUI?

Ron Zhang
  • 195
  • 1
  • 3
  • 17

0 Answers0