python使用tkinter實現(xiàn)屏幕中間倒計時
更新時間:2021年03月07日 09:32:17 作者:酷酷的波波
這篇文章主要為大家詳細介紹了python使用tkinter實現(xiàn)屏幕中間倒計時,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python實現(xiàn)屏幕中間倒計時的具體代碼,供大家參考,具體內(nèi)容如下
先看下效果圖:

代碼:
import time
from tkinter import Tk,Label
class TimeShow():#實現(xiàn)倒計時
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()
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python django 原生sql 獲取數(shù)據(jù)的例子
今天小編就為大家分享一篇python django 原生sql 獲取數(shù)據(jù)的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08
python pyinstaller打包exe報錯的解決方法
這篇文章主要給大家介紹了關(guān)于python pyinstaller打包exe報錯的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者使用python具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-11-11
使用Python將數(shù)組的元素導出到變量中(unpacking)
最近工作中遇到一個問題,需要利用Python將數(shù)組(list)或元組(tuple)中的元素導出到N個變量中,現(xiàn)在將我實現(xiàn)的方法分享給大家,有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-10-10
創(chuàng)建虛擬環(huán)境打包py文件的實現(xiàn)步驟
使用虛擬環(huán)境,可以為每個項目創(chuàng)建一個獨立的Python環(huán)境,每個環(huán)境都有自己的庫和版本,從而避免了依賴沖突,本文主要介紹了創(chuàng)建虛擬環(huán)境打包py文件的實現(xiàn)步驟,感興趣的可以了解一下2024-04-04

