在TKINTER设置.GIF映像时需要帮助



这是我到目前为止的代码:

from tkinter import *
root = Tk()
root.title("Skin")
def frame():
    f = Frame(root, height=350, width=400)
    f.pack_propagate(0)
    f.pack()
def credit():
    print("")
def image1():
    skin1 = PhotoImage(file='C:/Users/Xiam/Desktop/1.gif')
b = Button(root, text="Click here to see the diagram!", command=credit)
b.pack(fill=X, expand=2, anchor=N)
frame()
image1()
root.mainloop()

我知道这可能不是很有效,但是我只是在两分钟内就搅拌了。无论如何,我一直在尝试将" 1.GIF"图像在Dektop上显示在TKINTER窗口中,但它无法正常工作。根本。我在做什么错?

您正在创建一个图像对象,但是您没有在屏幕上显示它。您需要将其与标签小部件相关联,或将其嵌入画布或文本小部件中。创建图像对象时,可以创建标签图像,或者提前创建标签并在创建图像对象时更改标签。

例如:

skin1=PhotoImage(...)
the_label = Label(root, image=skin1)

-or-

the_label = Label(root)
...
skin1=PhotoImage(...)
the_label.configure(image=skin1)

最新更新