python使用tkinter實現(xiàn)屏幕中間倒計時
本文實例為大家分享了python實現(xiàn)屏幕中間倒計時的具體代碼,供大家參考,具體內(nèi)容如下
先看下效果圖:
代碼:
import timefrom tkinter import Tk,Labelclass 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)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. .NET中l(wèi)ambda表達式合并問題及解決方法2. JSP數(shù)據(jù)交互實現(xiàn)過程解析3. 淺談python出錯時traceback的解讀4. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法5. Python importlib動態(tài)導入模塊實現(xiàn)代碼6. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解7. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題8. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向9. Nginx+php配置文件及原理解析10. 在Android中使用WebSocket實現(xiàn)消息通信的方法詳解
