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 相关文章推荐
Python是编译运行的验证方法
Jan 30 Python
基于scrapy实现的简单蜘蛛采集程序
Apr 17 Python
Python编程中归并排序算法的实现步骤详解
May 04 Python
python基本语法练习实例
Sep 19 Python
Python字典创建 遍历 添加等实用基础操作技巧
Sep 13 Python
使用python将图片格式转换为ico格式的示例
Oct 22 Python
Django框架静态文件使用/中间件/禁用ip功能实例详解
Jul 22 Python
Python爬虫库BeautifulSoup的介绍与简单使用实例
Jan 25 Python
Python线程协作threading.Condition实现过程解析
Mar 12 Python
Python函数默认参数常见问题及解决方案
Mar 26 Python
利用Python将多张图片合成视频的实现
Nov 23 Python
python openssl模块安装及用法
Dec 06 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
一些需要禁用的PHP危险函数(disable_functions)
2012/02/23 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(五)
2014/06/23 PHP
PHP 导出Excel示例分享
2014/08/18 PHP
php文件上传后端处理小技巧
2016/05/22 PHP
laravel实现分页样式替换示例代码(增加首、尾页)
2017/09/22 PHP
PHP的mysqli_stmt_init()函数讲解
2019/01/24 PHP
可以把编码转换成 gb2312编码lib.UTF8toGB2312.js
2007/08/21 Javascript
JQuery+CSS提示框实现思路及代码(纯手工打造)
2013/05/07 Javascript
原生js制作简单的数字键盘
2015/04/24 Javascript
AngularJS中实现显示或隐藏动画效果的方式总结
2015/12/31 Javascript
Angularjs手动解析表达式($parse)
2016/10/12 Javascript
jquery实现全选、全不选以及单选功能
2017/03/23 jQuery
node.js实现微信JS-API封装接口的示例代码
2017/09/06 Javascript
微信小程序methods中定义的方法互相调用的实例代码
2018/08/07 Javascript
angular中子控制器向父控制器传值的实例
2018/10/08 Javascript
vue-router实现编程式导航的代码实例
2019/01/19 Javascript
JavaScript 作用域实例分析
2019/10/02 Javascript
构建大型 Vue.js 项目的10条建议(小结)
2019/11/14 Javascript
JavaScript变量基本使用方法实例分析
2019/11/15 Javascript
vue页面引入three.js实现3d动画场景操作
2020/08/10 Javascript
从零学Python之入门(四)运算
2014/05/27 Python
Python中.py文件打包成exe可执行文件详解
2017/03/22 Python
python使用itchat实现手机控制电脑
2018/02/22 Python
对numpy 数组和矩阵的乘法的进一步理解
2018/04/04 Python
python matlibplot绘制3D图形
2018/07/02 Python
python3 正则表达式基础廖雪峰
2020/03/25 Python
浅谈CSS3 动画卡顿解决方案
2019/01/02 HTML / CSS
css3实现动画的三种方式
2020/08/24 HTML / CSS
HTML5 文件上传下载的实例代码
2017/07/03 HTML / CSS
加拿大专业美发产品购物网站:Chatters
2021/02/28 全球购物
你经历的项目中的SCM配置项主要有哪些?什么是配置项?
2013/11/04 面试题
机械专业毕业生推荐信范文
2013/11/25 职场文书
中学生校园广播稿
2014/01/16 职场文书
党日活动总结
2014/05/07 职场文书
党员先锋岗事迹材料
2014/05/08 职场文书
5个实用的JavaScript新特性
2022/06/16 Javascript