import tkinter as tk
class GUIData:
def __init__(self) -> None:
self.boo= 0
self.windo = tk.Tk()
self.windo.geometry("200x200")
self.image1 = tk.PhotoImage(file="./gif/101.gif") #一定要指定file=路径
self.image = tk.PhotoImage(file="./gif/sam.gif") ##一定要指定file=路径不能载入
self.GuI()
def GuI(self):
self.lab = tk.Button(self.windo,height=40,width=40,
command=self.windo.destroy,image=self.image1)
self.lab.pack()
self.lab1= tk.Label(self.windo)
self.lab1.pack()
def gettime(self):
if self.boo:
self.lab.configure(image=self.image )
self.lab1.configure(image=self.image1)
self.boo=0
# print(self.boo)
else:
self.lab.configure(image=self.image1)
self.lab1.configure(image=self.image)
self.boo=1
self.windo.after(2000,self.gettime)#2秒切换一次
if __name__ == "__main__":
A = GUIData()
A.gettime()
A.windo.mainloop()
切换效果: