python 實(shí)現(xiàn)倒計(jì)時(shí)功能(gui界面)
運(yùn)行效果:

完整源碼:
##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的資訊、工具、實(shí)例,請(qǐng)關(guān)注python客棧
以上就是python 實(shí)現(xiàn)倒計(jì)時(shí)功能(gui界面)的詳細(xì)內(nèi)容,更多關(guān)于python 倒計(jì)時(shí)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- python實(shí)現(xiàn)倒計(jì)時(shí)的示例
- python實(shí)現(xiàn)倒計(jì)時(shí)小工具
- python實(shí)現(xiàn)的簡(jiǎn)單窗口倒計(jì)時(shí)界面實(shí)例
- python實(shí)現(xiàn)簡(jiǎn)單倒計(jì)時(shí)功能
- python實(shí)現(xiàn)七段數(shù)碼管和倒計(jì)時(shí)效果
- python使用tkinter實(shí)現(xiàn)屏幕中間倒計(jì)時(shí)
- python實(shí)現(xiàn)windows倒計(jì)時(shí)鎖屏功能
- 親手教你用Python打造一款摸魚倒計(jì)時(shí)界面
- python基于tkinter制作下班倒計(jì)時(shí)工具
- 基于Python實(shí)現(xiàn)倒計(jì)時(shí)工具
相關(guān)文章
TensorFlow實(shí)現(xiàn)模型斷點(diǎn)訓(xùn)練,checkpoint模型載入方式
這篇文章主要介紹了TensorFlow實(shí)現(xiàn)模型斷點(diǎn)訓(xùn)練,checkpoint模型載入方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-05-05
python3 實(shí)現(xiàn)在運(yùn)行的時(shí)候隱藏命令窗口
這篇文章主要介紹了python3 實(shí)現(xiàn)在運(yùn)行的時(shí)候隱藏命令窗口方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05
PyQt6/PySide6 的 QPropertyAnimation 類適用場(chǎng)景分析
QGraphicsView和QGraphicsScene是Qt圖形視圖框架的核心類,用于構(gòu)建高性能、可交互的2D圖形界面,QGraphicsView 和 QGraphicsScene 為復(fù)雜圖形應(yīng)用提供了強(qiáng)大支持,本文給大家介紹PyQt6/PySide6 的 QPropertyAnimation 類,感興趣的朋友一起看看吧2025-03-03
python實(shí)現(xiàn)簡(jiǎn)單的學(xué)生成績(jī)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡(jiǎn)單的學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
python腳本設(shè)置系統(tǒng)時(shí)間的兩種方法
這篇文章主要介紹了python腳本設(shè)置系統(tǒng)時(shí)間的兩種方法,其一是調(diào)用socket直接發(fā)送udp包到國(guó)家授時(shí)中心,其二是調(diào)用ntplib包,感興趣的小伙伴們可以參考一下2016-02-02
Python 實(shí)現(xiàn)定積分與二重定積分的操作
這篇文章主要介紹了Python 實(shí)現(xiàn)定積分與二重定積分的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05
python自動(dòng)化定位的9種函數(shù)方法小結(jié)
對(duì)于python進(jìn)行自動(dòng)化定位有9種方法,這篇文章主要來(lái)和大家聊聊這9種方法的具體使用,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2024-11-11


