python 实现倒计时功能(gui界面)


Posted in Python onNovember 11, 2020

运行效果:

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客栈

python 实现倒计时功能(gui界面)

以上就是python 实现倒计时功能(gui界面)的详细内容,更多关于python 倒计时的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
在Django中创建第一个静态视图
Jul 15 Python
Python实现一个转存纯真IP数据库的脚本分享
May 21 Python
python爬虫_实现校园网自动重连脚本的教程
Apr 22 Python
python爬虫正则表达式之处理换行符
Jun 08 Python
解决python3运行selenium下HTMLTestRunner报错的问题
Dec 27 Python
Python使用LDAP做用户认证的方法
Jun 20 Python
基于Django ORM、一对一、一对多、多对多的全面讲解
Jul 26 Python
pytorch点乘与叉乘示例讲解
Dec 27 Python
python3光学字符识别模块tesserocr与pytesseract的使用详解
Feb 26 Python
python 实现 hive中类似 lateral view explode的功能示例
May 18 Python
Python3读写ini配置文件的示例
Nov 06 Python
Python安装Bs4的多种方法
Nov 28 Python
windows+vscode安装paddleOCR运行环境的步骤
Nov 11 #Python
Django基于Models定制Admin后台实现过程解析
Nov 11 #Python
Django Admin后台模型列表页面如何添加自定义操作按钮
Nov 11 #Python
Django启动时找不到mysqlclient问题解决方案
Nov 11 #Python
Python+logging输出到屏幕将log日志写入文件
Nov 11 #Python
通过Django Admin+HttpRunner1.5.6实现简易接口测试平台
Nov 11 #Python
Django自定义YamlField实现过程解析
Nov 11 #Python
You might like
sourcesafe管理phpproj文件的补充说明(downmoon)
2009/04/11 PHP
PHP URL路由类实例
2013/11/12 PHP
php实现快速排序的三种方法分享
2014/03/12 PHP
php结合ACCESS的跨库查询功能
2015/06/12 PHP
php图片上传类 附调用方法
2016/05/15 PHP
php实现图片上传时添加文字和图片水印技巧
2020/04/18 PHP
Yii2框架dropDownList下拉菜单用法实例分析
2016/07/18 PHP
php-msf源码详解
2017/12/25 PHP
基于Jquery的文字自动截取(提供源代码)
2011/08/09 Javascript
JQuery EasyUI 数字格式化处理示例
2014/05/05 Javascript
Jquery左右滑动插件之实现超级炫酷动画效果附源码下载
2015/12/02 Javascript
JavaScript 限制文本框不可输入英文单双引号的方法
2016/12/20 Javascript
jQuery DateTimePicker 日期和时间插件示例
2017/01/22 Javascript
ES6新特性之字符串的扩展实例分析
2017/04/01 Javascript
Bootstrap实现的标签页内容切换显示效果示例
2017/05/25 Javascript
react 父组件与子组件之间的值传递的方法
2017/09/14 Javascript
Vue axios 将传递的json数据转为form data的例子
2019/10/29 Javascript
jQuery实现的图片点击放大缩小功能案例
2020/01/02 jQuery
javaScript 实现重复输出给定的字符串的常用方法小结
2020/02/20 Javascript
[40:50]2014 DOTA2国际邀请赛中国区预选赛 5 23 CIS VS LGD第四场
2014/05/24 DOTA
[02:32]DOTA2亚洲邀请赛 C9战队出场宣传片
2015/02/07 DOTA
[03:24]CDEC.Y赛前采访 努力备战2016国际邀请赛中国区预选赛
2016/06/25 DOTA
Python制作简单的网页爬虫
2015/11/22 Python
Python的Flask框架中的Jinja2模板引擎学习教程
2016/06/30 Python
老生常谈python的私有公有属性(必看篇)
2017/06/09 Python
浅谈Python对内存的使用(深浅拷贝)
2018/01/17 Python
Django框架设置cookies与获取cookies操作详解
2019/05/27 Python
Pandas —— resample()重采样和asfreq()频度转换方式
2020/02/26 Python
python获取本周、上周、本月、上月及本季的时间代码实例
2020/09/08 Python
基于Pytorch版yolov5的滑块验证码破解思路详解
2021/02/25 Python
几个CSS3的flex弹性盒模型布局的简单例子演示
2016/05/12 HTML / CSS
Zavvi美国:英国娱乐之家
2017/03/19 全球购物
Hawes & Curtis官网:英国经典品牌
2019/07/27 全球购物
Perfume’s Club美国官网:西班牙第一家在线美容店
2020/06/10 全球购物
工作违纪检讨书
2014/02/17 职场文书
学校国庆节活动总结
2015/03/23 职场文书