您好,登錄后才能下訂單哦!
如何在python中利用tkinter在屏幕中間實現(xiàn)一個倒計時功能?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
Python主要應(yīng)用于:1、Web開發(fā);2、數(shù)據(jù)科學(xué)研究;3、網(wǎng)絡(luò)爬蟲;4、嵌入式應(yīng)用開發(fā);5、游戲開發(fā);6、桌面應(yīng)用開發(fā)。
代碼:
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()
關(guān)于如何在python中利用tkinter在屏幕中間實現(xiàn)一個倒計時功能問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。