如何在python中利用tkinter在屏幕中间实现一个倒计时功能?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。
代码:
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中利用tkinter在屏幕中间实现一个倒计时功能问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。