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 相关文章推荐
使用scrapy实现爬网站例子和实现网络爬虫(蜘蛛)的步骤
Jan 23 Python
python 写的一个爬虫程序源码
Feb 28 Python
Python heapq使用详解及实例代码
Jan 25 Python
Python 3中print函数的使用方法总结
Aug 08 Python
Python中表示字符串的三种方法
Sep 06 Python
Django 中使用流响应处理视频的方法
Jul 20 Python
python Kmeans算法原理深入解析
Aug 23 Python
浅谈tensorflow中Dataset图片的批量读取及维度的操作详解
Jan 20 Python
将python字符串转化成长表达式的函数eval实例
May 11 Python
python3通过qq邮箱发送邮件以及附件
May 20 Python
python 制作网站筛选工具(附源码)
Jan 21 Python
Python如何让字典保持有序排列
Apr 29 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提交后跳转
2013/06/23 PHP
php+mysqli数据库连接的两种方式
2015/01/28 PHP
JavaScript实现删除电脑的关机键
2016/07/26 PHP
Ubuntu VPS中wordpress网站打开时提示”建立数据库连接错误”的解决办法
2016/11/03 PHP
用PHP的socket实现客户端到服务端的通信实例详解
2017/02/04 PHP
Yii2实现UploadedFile上传文件示例
2017/02/15 PHP
javascript将数组插入到另一个数组中的代码
2013/01/10 Javascript
dwz 如何去掉ajaxloading具体代码
2013/05/22 Javascript
模拟多级复选框效果的jquery代码
2013/08/13 Javascript
禁止选中文字兼容IE、Chrome、FF等
2013/09/04 Javascript
js判断url是否有效的两种方法
2014/03/04 Javascript
《JavaScript DOM 编程艺术》读书笔记之JavaScript 语法
2015/01/09 Javascript
jQuery增加与删除table列的方法
2016/03/01 Javascript
dropload.js插件下拉刷新和上拉加载使用详解
2017/10/20 Javascript
JS 实现微信扫一扫功能
2018/09/14 Javascript
jquery操作select常见方法大全【7种情况】
2019/05/28 jQuery
layui 表单标签的校验方法
2019/09/04 Javascript
Python将xml和xsl转换为html的方法
2015/03/10 Python
在Python中处理字符串之ljust()方法的使用简介
2015/05/19 Python
python3编写ThinkPHP命令执行Getshell的方法
2019/02/26 Python
python3+selenium自动化测试框架详解
2019/03/17 Python
pyinstaller打包单个exe后无法执行错误的解决方法
2019/06/21 Python
Django项目之Elasticsearch搜索引擎的实例
2019/08/21 Python
python中的数组赋值与拷贝的区别详解
2019/11/26 Python
pytorch数据预处理错误的解决
2020/02/20 Python
Python使用tkinter实现小时钟效果
2021/02/22 Python
CSS3+font字体文件实现圆形半透明菜单具体步骤(图解)
2013/06/03 HTML / CSS
澳大利亚购买最佳炊具品牌网站:Cookware Brands
2019/02/16 全球购物
如何通过jdbc调用存储过程
2012/04/19 面试题
会议接待欢迎词
2014/01/12 职场文书
会计专业自我评价
2014/02/12 职场文书
小学生思想品德评语
2014/12/31 职场文书
房租涨价通知
2015/04/23 职场文书
小平小道观后感
2015/06/09 职场文书
《飘》英文读后感五篇
2019/10/11 职场文书
windows11怎么查看自己安装的版本号? win11版本号的查看方法
2021/11/21 数码科技