Tkinter 带图片按键,标签制作

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

切换效果:

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值