1

Im trying to present an image inside a label, although when I print the label there is no image inside it. Here is my code.

from tkinter import *
newGameWindow = Toplevel()
newGameWindow.title("New Game")
newGameWindow.config(bg = "grey")
newGameWindow.geometry('600x600')


#courtImg = PhotoImage('basketballCourtTemplate.png')
courtImg = PhotoImage(file ='basketballCourtTemplate.png')


photo = Label(newGameWindow, image= courtImg, height = 200, width =200)

photo.pack()

newGameWindow.mainloop()

the image is located in the same file as the code. Am I loading in the image correctly?

EDIT: this code produces exactly the same output.

from tkinter import *
newGameWindow = Toplevel()
newGameWindow.title("New Game")
newGameWindow.config(bg = "grey")
newGameWindow.geometry('600x600')


courtImg = PhotoImage('basketballCourtTemplate.gif')


photo = Label(newGameWindow, image= courtImg, height = 200, width =200)
photo.image = courtImg
photo.pack()

newGameWindow.mainloop()

EDIT: All it needed was courtImg = PhotoImage(file='basketballCourtTemplate.gif')

진민수
  • 1
  • 2
H_Lev1
  • 253
  • 4
  • 18
  • [Why do my Tkinter images not appear?](http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm) – Lafexlos Nov 18 '16 at 11:24

0 Answers0