python 实现倒计时功能(gui界面)
作者:TechVidvan 发布时间:2021-03-05 14:19:55
标签:python,倒计时,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()
想要获得更多关于python的资讯、工具、实例,请关注python客栈
来源:https://techvidvan.com/tutorials/countdown-clock-timer-python/


猜你喜欢
- /**//// <summary> /// 生成带CDATA的节点 /// </summary> /// <p
- 谢谢icedblog提供的代码, 从那个js中我参考了moveSelect的利用, 不过那个代码中有几个BUG, 比如按住鼠标不放会不见显示
- 一. XSL入门1.XSL---XML的样式表 HTML网页使用预先确定的标识(tags),这就是说所有的标记都有明确的含义,例如<p
- Character 字符串:数据类型描述存储char(n)固定长度的字符串。最多 8,000 个字符。nvarchar(n)可变长度的字符串
- 前言体能状态先于精神状态,习惯先于决心,聚焦先于喜好。SHA算法简介1.1 概述SHA (Secure Hash Algorithm,译作安
- 自动追踪算法,在我们设计2D射击类游戏时经常会用到,这个听起来很高大上的东西,其实也并不是军事学的专利,在数学上解决的话需要去解微分方程,这
- 介绍今天有个不正经的需求,就是要快速做一个restful api的性能测试,要求测试在海量作业数据的情况下客户端分页获取所有作业的性能。因为
- 前言本人在学习go-micro中,用到Makefile,本人之前用过Makefile,但是不知道为什么这会就不能用了,我找了好多教程都没能解
- 本文实例讲述了Python基于pygame实现的font游戏字体。分享给大家供大家参考,具体如下:在pygame游戏开发中,一个友好的UI中
- 一、Pytest简介Pytest is a mature full-featured Python testing tool that he
- 本文实例讲述了Zend Framework教程之Zend_Config_Ini用法。分享给大家供大家参考,具体如下:Zend_Config_
- 数据解析数据解析就是将爬取到的整个页面中的局部的内容进行提取。python中常用的数据解析方式有以下三种:bs4(python中独有的)xp
- 安装pip install pyshp引入import shapefile读取sf=shapefile.Reader("{路径名}
- 我们经常使用nodeType==1判断元素是否是一个HMTLElement元素。页面上的元素都是节点(Node),有元素节点(Element
- 如下所示:import pydicom import matplotlib.pyplot as plt import scipy.misc
- FORMAT() 函数用于对字段的显示进行格式化。SQL FORMAT() 语法SELECT FORMAT(column_name,form
- <%'使用说明'Dim a'Set a=new CreateExce
- 这个问题是py2和py3兼容性的问题在py2中,判断key是否属于dict的写法可以是:d={'name':'abc
- 楔子pandas 支持我们从 Excel、CSV、数据库等不同数据源当中读取数据,来构建 DataFrame。但有时数据并不来自这些外部数据
- 在支持FSO的情况下,可以显示本站内的所有ASP页面的代码适用于代码演示时在效果页面上直接显示该页面的代码而不用再对代码制作专门的页面使用方