简体   繁体   中英

Tkinter Image not showing up

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()

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM