运行效果:

完整源码:

##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 倒计时的资料请关注脚本之家其它相关文章!

python 倒计时功能怎么用print实现_python 实现倒计时功能(gui界面)相关推荐

  1. python统计西游记人物名字出现次数_Python文本统计功能之西游记用字统计操作

    这篇文章主要介绍了Python文本统计功能之西游记用字统计操作,结合实例形式分析了Python文本读取.遍历.统计等相关操作技巧,需要的朋友可以参考下 本文实例讲述了Python文本统计功能之西游记用 ...

  2. python统计西游记人物名字出现次数_Python文本统计功能之西游记用字统计操作示例...

    本文实例讲述了Python文本统计功能之西游记用字统计操作.分享给大家供大家参考,具体如下: 一.数据 xyj.txt,<西游记>的文本,2.2MB 致敬吴承恩大师,4020行(段) 二. ...

  3. python实验报告内容实现购物车系统_Python 实践--购物车功能简单实现

    实验环境: operating system: Centos 6.3 Python version:Python 2.6.6 知识点: Python 基本数据类型的常用操作 #!/usr/bin/en ...

  4. python如何用色度表示数值大小_python入门004数字(例程界面很清晰大小也合适)

    (例程界面很清晰大小也合适) https://m.toutiao.com/is/JEFkLTv/ python入门004:数字 一.整数和浮点数 1.整数 在python中,可以对整数执行加(+)减( ...

  5. python中gui实现一个登录界面_Python:简单的登陆GUI界面

    import tkinter import sys import re top = tkinter.Tk() top.geometry('400x170+350+150') top.wm_title( ...

  6. python登录页面_Python:简单的登陆GUI界面

    import tkinter import sys import re top = tkinter.Tk() top.geometry('400x170+350+150') top.wm_title( ...

  7. python时间倒计时显示屏厂家_python 实现倒计时功能(gui界面)

    运行效果: 完整源码: ##import library from tkinter import * import time from playsound import playsound ## di ...

  8. python print 换行_Python学习 | Python的基础语法

    Python 语言与 Perl,C 和 Java 等语言有许多相似之处.但是,也存在一些差异,编写Paython程序之前需要对语法有所了解,才能编写规范的Python程序. 一.行和缩进 Python ...

  9. python输入格式一个不带小数点_Python输入input、输出print

    1.输入input input是用于输入数据给变量.通过键盘输入的是字符串,如果需要其他格式,需要做转换.比如int.float类型数据,int() 如下是一个例子: 如果a不进行int转换,那么输入 ...

最新文章

  1. 新工具一键安装Java环境!微软又双叒叕造福开发者
  2. 修补分支提交注意事项
  3. SpringMVC返回json是设置编辑等消息头,消息头信息介绍(respone.setHeader,这个从网上获取)
  4. 大牛书单 | 腾讯运维大咖陪你过724
  5. 可关闭的浮动div示例
  6. c++里解决“控制传输跳过的实例化”的方法
  7. Erlang实战练习(一)
  8. 63 岁工程师的退休生活:开发一款计算器应用,22 天获 56800 下载!
  9. pdfjs实现pdf预览
  10. WPS安装office自定义项安装期间出错
  11. Science:无氧世界的古菌氨氧化
  12. APP推广要做哪些?渠道?方案?竞争分析?
  13. 使用AIDL实现Android的跨进程通信
  14. HTTP和AJAX重点知识
  15. 基于android的轻餐饮点餐APP(ssm+uinapp+Mysql)
  16. ZXing 生成二维码和条形码
  17. 2014 Hulu Upfront Updates
  18. [GridView]解决js-xlsx导出Excel时数字太长变为科学计数的问题
  19. ABP框架心得系列-1.本土化和ABP核心
  20. 初始Android动画

热门文章

  1. Shell中要如何调用别的shell脚本
  2. MyBatis之传入参数——parameterType
  3. 第八章 让开发板发出声音:蜂鸣器驱动读后感
  4. mac下没有设置 SVN_EDITOR....错误解决方法
  5. U盘系统启动制作Windows版,蒋介石制作
  6. POJ 2186 Popular Cows
  7. 计算机常用英语术语、词汇表(上)
  8. java 回滚异常_回滚事务并关闭抛出异常的连接
  9. voliate修饰数组有作用吗_Arrays.asList()真的就把数组转换为了List集合吗?
  10. 计算机二级的考试c模板,2013年9月全国计算机等级《二级C++》上机模考试卷(5)