网络编程
位置:首页>> 网络编程>> Python编程>> python使用tkinter实现屏幕中间倒计时

python使用tkinter实现屏幕中间倒计时

作者:酷酷的波波  发布时间:2021-03-10 22:28:11 

标签:python,tkinter,倒计时

本文实例为大家分享了python实现屏幕中间倒计时的具体代码,供大家参考,具体内容如下

先看下效果图:

python使用tkinter实现屏幕中间倒计时

代码:


import time
from tkinter import Tk,Label

class TimeShow():#实现倒计时

def __init__(self,time_show=5):
   self.timeShowWin=Tk()
   self.timeShowWin.overrideredirect(True)
   self.timeShowWin.attributes('-alpha',1)
   self.timeShowWin.attributes('-topmost',True)
   self.timeShowWin.attributes('-transparentcolor','black')  
   self.time_show = time_show
   self.time_label=Label(self.timeShowWin,text='倒计时{}秒'.format(self.time_show),font=('楷体',25),fg='red',bg='black')
   self.time_label.pack(fill='x',anchor='center')
   self.timeShowWin.geometry('+'+str(int(self.timeShowWin.winfo_screenwidth()/2))+'+'+str(125))
   self.timeShowWin.after(1,self.show)

def show(self):
   while self.time_show >= 0:
     print('time_label={}'.format(self.time_label))
     self.time_label['text']= '倒计时{}秒'.format(self.time_show)
     self.timeShowWin.update()
     self.time_show -= 1
     time.sleep(1)
   self.timeShowWin.destroy()

def start(self):
   print('ok')
   self.timeShowWin.mainloop()

if __name__ == '__main__':
 a=TimeShow(10)
 a.start()

来源:https://blog.csdn.net/qq_39758896/article/details/114367700

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com