繁体   English   中英

Tkinter 图像未显示

[英]Tkinter Image not showing up

我对编码很陌生,我正在尝试在 tkinter window 中显示图像。

但是,当我运行下面的代码时,图像应该在哪里。 我也没有从这段代码中得到任何错误。

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

试试 josav09 对这个问题的回答: 如何在 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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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