Python tkinter PhotoImage 无法正常工作

Dan*_*iel 5 python tkinter python-3.x

我正在尝试使用 tkinter,但这段代码不起作用,我想知道是否有人知道为什么,谢谢。

from tkinter import *
window = Tk()
window.title("tkinter stuff")
photo1 = PhotoImage("file=hs.gif")
Label(window, image=photo1).grid(row=0,column=0,sticky=W)
window.mainloop()
Run Code Online (Sandbox Code Playgroud)

澄清一下,出现了一个标题为“tkinter stuff”的窗口,但图像没有显示。另外,在与我的代码相同的文件夹中还有一个名为“hs.gif”的文件。

谢谢您的帮助

PRM*_*reu 4

您需要移动引号:

photo1 = PhotoImage(file="hs.gif")
Run Code Online (Sandbox Code Playgroud)