1

I'm quite new to coding and I'm trying to have an image show up in a tkinter window.

However, when I run the code below there is the gap where the image should be. I am getting no error from this code as well.

window2 = Toplevel()
window2.geometry("1920x1200")

Namearea = Label(window2, text="Please Name the Prebuild:")
Namearea.pack()

e = Entry(window2, width=50, borderwidth=3, bg="Light Grey", fg="black")
e.pack()

#Here is the part that is not working.
img3 = PhotoImage(file=r"C:\\Tkinter\\ComputerImage.png")
picture1 = Label(window2, image=img3)
picture1.pack()

SaveAndContinue = Button(window2, text="Save and Return to Main Menu", padx=75, pady=20, bg="Light Grey")
SaveAndContinue.pack()
Leo Qi
  • 557
  • 5
  • 13
Rhys34512
  • 39
  • 5

1 Answers1

3

Try the answer from josav09 for this question: How to add an image in Tkinter?

from tkinter import *
from PIL import ImageTk, Image
import os

root = Tk()
img = ImageTk.PhotoImage(Image.open("True1.gif"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()
SuzukiBKing
  • 178
  • 8
  • It says no module named 'PIL'? – Rhys34512 Aug 11 '20 at 00:26
  • 1
    Not the poster, but you will have to install it if you do not have it, through pip. The maintaned library is now called [Pillow](https://pypi.org/project/Pillow). See https://effbot.org/tkinterbook/photoimage.htm for more details about the Tkinter PhotoImage class and PIL – Leo Qi Aug 11 '20 at 00:38