国庆假期快到了,想查查还有几天几小时到假期,这对程序员小菜一碟,轻轻松松用python写个倒计时程序(天、时、分、秒),助你熬到假期!
下载安装python3.9.6,进入python官方网站://www.python.org/
点击Python 3.9.6
直接安装即可。
按win+R输入cmd,打开控制台,输入python -V,输出python版本号说明安装成功。
##import libraryfrom tkinter import *import timefrom datetime import datetime,timedelta################GUI to display window ##########################root = Tk()root.geometry("450x300")root.resizable(0,0)root.config(bg ="blanched almond")root.title("国庆倒计时")Label(root, text = "国庆倒计时" , font = "arial 20 bold", bg ="papaya whip").pack()############GUI to display current time#######################Label(root, font ="arial 15 bold", text = " 当前时间:", bg = "papaya whip").place(x = 40 ,y = 70)#######################GUI to set the future time ##########Label(root, font ="arial 15 bold", text = " 到达时间:", bg = "papaya whip").place(x = 40 ,y = 110)#set yearyear_set = StringVar()Entry(root, textvariable =year_set , width = 4, font = "arial 12").place(x=175, y=115)Label(root, font ="arial 15", text = "-", bg = "papaya whip").place(x = 215 ,y = 110)year_set.set("0000")#set monthmonth_set= StringVar()Entry(root, textvariable =month_set, width =2, font = "arial 12").place(x=235, y=115)Label(root, font ="arial 15", text ="-", bg = "papaya whip").place(x = 260 ,y = 110)month_set.set("00")#set dayday_set= StringVar()Entry(root, textvariable =day_set, width =2, font = "arial 12").place(x=275, y=115)day_set.set("00")# set hourhour_set= StringVar()Entry(root, textvariable =hour_set, width =2, font = "arial 12").place(x=305, y=115)Label(root, font ="arial 15", text = ":", bg = "papaya whip").place(x = 330 ,y = 110)hour_set.set("00")# set minmin_set= StringVar()Entry(root, textvariable =min_set, width =2, font = "arial 12").place(x=345, y=115)Label(root, font ="arial 15", text = ":", bg = "papaya whip").place(x = 370 ,y = 110)min_set.set("00")# set secsec_set= StringVar()Entry(root, textvariable =sec_set, width =2, font = "arial 12").place(x=385, y=115)sec_set.set("00")#######################GUI to display timer countdown ##########Label(root, font ="arial 15 bold", text = " 倒计时:", bg ="papaya whip").place(x = 40 ,y = 150)#storing secondssec = StringVar()Entry(root, textvariable = sec, width = 2, font = "arial 12").place(x=325, y=155)Label(root, font ="arial 15", text = "秒", bg = "papaya whip").place(x = 350 ,y = 150)sec.set("00")#storing minutesmins= StringVar()Entry(root, textvariable = mins, width =2, font = "arial 12").place(x=275, y=155)Label(root, font ="arial 15", text = "分", bg = "papaya whip").place(x = 300 ,y = 150)mins.set("00")# storing hourshrs= StringVar()Entry(root, textvariable = hrs, width =2, font = "arial 12").place(x=225, y=155)Label(root, font ="arial 15", text = "时", bg = "papaya whip").place(x = 250 ,y = 150)hrs.set("00")# storing daysdays= StringVar()Entry(root, textvariable = days, width =2, font = "arial 12").place(x=175, y=155)Label(root, font ="arial 15", text = "天", bg = "papaya whip").place(x = 200 ,y = 150)days.set("00")#########fun to display current time#############def clock(): clock_time = time.strftime("%Y-%m-%d %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 = 175 , y = 70)clock()##########fun to start countdown########def countdown(): #now = datetime.now() #end = datetime((year_set).get(),(month_set).get(),(day_set).get(),(hour_set).get(),(min_set).get(),(sec_set).get(),00); global seconds_now now = time.time() lt_ = time.strptime(f"{(year_set).get()} {(month_set).get()} {(day_set).get()} {(hour_set).get()} {(min_set).get()} {(sec_set).get()}", "%Y %m %d %H %M %S") end = time.mktime(lt_) times=int (end-now) #.total_seconds()); while times > -1: minute,second = (times // 60 , times % 60) hour = 0 if minute > 60: hour , minute = (minute // 60 , minute % 60) day=0 if hour>24: day,hour=(hour//24,hour%24) sec.set(second) mins.set(minute) hrs.set(hour) days.set(day) root.update() time.sleep(1) times -= 1Button(root, text="START", bd ="5", command = countdown, bg = "antique white", font = "arial 10 bold").place(x=150, y=210) root.mainloop()
打开工程文件,在地址栏里输入cmd,按Enter回车,即打开控制台。
输入python main.py,按回车就打开了程序GUI界面。
到达时间填2021年10月1日,按start按钮,就开始放假倒计时啦!
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/121688.html
摘要:战争已胜,精神依在,当延续了这份坚韧与毅力之后,所有事情都将变得有无限可能,本期成功就业的小余,正是凭借着这股毅力,完成了梦想,取得了高薪。 伴随着7天国庆长假落...
摘要:因为操作系统一直被看做是计算机软件的基石。本系列是我学习操作系统的笔记,操作系统是以为例子。其他的操作系统也是差不多。将设备驱动一共分为个级别,每个级别的驱动初始化声明宏定义及其在系统启动过程中的启动顺序如下表所示。 老板说我技术需要有长进,不能只做一个crud boy。 于是我选来选去,...
摘要:接下来,我主要从三个阶段回顾我的秋招,分别是前期中期尾声。到了这里,我的秋招算是正式的尘埃落定了,签完三方后,我的秋招结束了。四复盘总结这次的复盘主要是我自己整个秋招的历程缩影,很多细节无法在一篇文章就说清楚。 ...
?阶段一:回顾过往 好久没有更新博客了?(鸽了太久),嘿嘿,感觉是时候回过头来写一篇了...... 主要是因为国庆假期快过去了,才发现自己好像什么事都没有开始做。确实深有体会:人越长大,时间过得越快,当下的我就处在时间飞逝的浮光掠影之中...... 后端的基础经过一年多的不断学习,渐渐进入了尾声...终于在国庆不久前进入了分布式、SpingCloud...
阅读 1032·2021-11-25 09:43
阅读 667·2021-11-22 14:45
阅读 3780·2021-09-30 09:48
阅读 1024·2021-08-31 09:41
阅读 1936·2019-08-30 13:52
阅读 1947·2019-08-30 11:24
阅读 1304·2019-08-30 11:07
阅读 904·2019-08-29 12:15