python 實現(xiàn)倒計時功能(gui界面)
運行效果:
完整源碼:
##import library from tkinter import * import time from playsound import playsound ## display window root = Tk() root.geometry('400x300') root.resizable(0,0) root.config(bg ='blanched almond') root.title('TechVidvan - Countdown Clock And Timer') Label(root, text = 'Countdown Clock and Timer' , font = 'arial 20 bold', bg ='papaya whip').pack() #display current time####################### Label(root, font ='arial 15 bold', text = 'current time :', bg = 'papaya whip').place(x = 40 ,y = 70) ####fun to display current time def clock(): clock_time = time.strftime('%H:%M:%S %p') curr_time.config(text = clock_time) curr_time.after(1000,clock) curr_time =Label(root, font ='arial 15 bold', text = '', fg = 'gray25' ,bg ='papaya whip') curr_time.place(x = 190 , y = 70) clock() #######################timer countdown########## #storing seconds sec = StringVar() Entry(root, textvariable = sec, width = 2, font = 'arial 12').place(x=250, y=155) sec.set('00') #storing minutes mins= StringVar() Entry(root, textvariable = mins, width =2, font = 'arial 12').place(x=225, y=155) mins.set('00') # storing hours hrs= StringVar() Entry(root, textvariable = hrs, width =2, font = 'arial 12').place(x=200, y=155) hrs.set('00') ##########fun to start countdown def countdown(): times = int(hrs.get())*3600+ int(mins.get())*60 + int(sec.get()) while times > -1: minute,second = (times // 60 , times % 60) hour = 0 if minute > 60: hour , minute = (minute // 60 , minute % 60) sec.set(second) mins.set(minute) hrs.set(hour) root.update() time.sleep(1) if(times == 0): playsound('Loud_Alarm_Clock_Buzzer.mp3') sec.set('00') mins.set('00') hrs.set('00') times -= 1 Label(root, font ='arial 15 bold', text = 'set the time', bg ='papaya whip').place(x = 40 ,y = 150) Button(root, text='START', bd ='5', command = countdown, bg = 'antique white', font = 'arial 10 bold').place(x=150, y=210) root.mainloop()
想要獲得更多關(guān)于python的資訊、工具、實例,請關(guān)注python客棧
以上就是python 實現(xiàn)倒計時功能(gui界面)的詳細(xì)內(nèi)容,更多關(guān)于python 倒計時的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
tensorflow學(xué)習(xí)教程之文本分類詳析
初學(xué)tensorflow,借鑒了很多別人的經(jīng)驗,參考博客對評論分類(感謝博主的一系列好文),本人也嘗試著實現(xiàn)了對文本數(shù)據(jù)的分類,下面這篇文章主要給大家介紹了關(guān)于tensorflow學(xué)習(xí)教程之文本分類的相關(guān)資料,需要的朋友可以參考下2018-08-08Pymysql實現(xiàn)往表中插入數(shù)據(jù)過程解析
這篇文章主要介紹了Pymysql實現(xiàn)往表中插入數(shù)據(jù)過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-06-06使用Python將字符串轉(zhuǎn)換為格式化的日期時間字符串
這篇文章主要介紹了使用Python將字符串轉(zhuǎn)換為格式化的日期時間字符串,需要的朋友可以參考下2019-09-09使用python telnetlib批量備份交換機配置的方法
今天小編就為大家分享一篇使用python telnetlib批量備份交換機配置的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07Python實現(xiàn)服務(wù)端渲染SSR的示例代碼
服務(wù)端渲染是一種常見的技術(shù)策略,特別是在需要改善網(wǎng)站的搜索引擎優(yōu)化(SEO)和首屏加載時間的場景下,本文將介紹如何利用?Python?實現(xiàn)?SSR,感興趣的可以了解下2024-02-02PyQt5實現(xiàn)用戶登錄GUI界面及登錄后跳轉(zhuǎn)
PyQt5是強大的GUI工具之一,通過其可以實現(xiàn)優(yōu)秀的桌面應(yīng)用程序。本文主要介紹了PyQt5實現(xiàn)用戶登錄GUI界面及登錄后跳轉(zhuǎn),具有一定的參考價值,感興趣的可以了解一下2021-11-11Python檢查判斷一個數(shù)是不是另一個數(shù)的整數(shù)次冪實例深究
在數(shù)學(xué)和計算中,確定一個數(shù)是否為另一個數(shù)的整數(shù)次冪是一個常見而重要的問題,例如,我們可能需要判斷一個數(shù)是否是某個數(shù)的平方、立方或其他冪次,本文將探討在Python中如何實現(xiàn)這一功能,通過數(shù)學(xué)方法和算法檢查一個數(shù)是否是另一個數(shù)的整數(shù)次冪2023-12-12