python使用tkinter实现屏幕中间倒计时
更新时间:2021年03月07日 09:32:17 作者:酷酷的波波
这篇文章主要为大家详细介绍了python使用tkinter实现屏幕中间倒计时,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了python实现屏幕中间倒计时的具体代码,供大家参考,具体内容如下
先看下效果图:

代码:
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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
python pyinstaller打包exe报错的解决方法
这篇文章主要给大家介绍了关于python pyinstaller打包exe报错的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者使用python具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧2019-11-11
使用Python将数组的元素导出到变量中(unpacking)
最近工作中遇到一个问题,需要利用Python将数组(list)或元组(tuple)中的元素导出到N个变量中,现在将我实现的方法分享给大家,有需要的朋友们可以参考借鉴,下面来一起看看吧。2016-10-10


最新评论