本文实例为大家分享了python实现屏幕中间倒计时的具体代码,供大家参考,具体内容如下
先看下效果图:
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
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