如何使用python写个国庆假期倒计时程序
发表于:2025-02-19 作者:千家信息网编辑
千家信息网最后更新 2025年02月19日,这篇文章主要介绍了如何使用python写个国庆假期倒计时程序,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。一、先看效果:二、安装pyt
千家信息网最后更新 2025年02月19日如何使用python写个国庆假期倒计时程序
这篇文章主要介绍了如何使用python写个国庆假期倒计时程序,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
一、先看效果:
二、安装python:
1、下载安装python
下载安装python3.9.6,进入python官方网站:http://www.python.org/
点击Python 3.9.6
直接安装即可。
2、验证安装成功。
按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 -= 1 Button(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按钮,就开始放假倒计时啦!
感谢你能够认真阅读完这篇文章,希望小编分享的"如何使用python写个国庆假期倒计时程序"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!
倒计时
国庆
篇文章
输入
程序
时间
成功
控制台
控制
代码
价值
兴趣
同时
地址
官方
官方网站
工程
按钮
效果
文件
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
交换机网络安全产品
dayz刷不出服务器
泰兴进口网络技术参考价格
我国网络安全信息的法律法规
科技的最高境界就是互联网吗
攻城英雄无网络或服务器不可用
数据库非模糊查询语录
职业学校网络安全自查报告
万方数据库如何订制
奇安信网络安全领导
软件开发的系统风险
sql数据库无日志不能附加
数据库技术及应用上机考试题
工会网络安全领导小组
南宁市计算机软件开发公司
pg数据库执行计划怎么看
互联网科技创新的方法路径
创造与魔法台服哪个服务器好
网络安全护航 强国
怎么打开电脑服务器管理器
莱州平台软件开发公司有哪些
网络安全伴我行作文
互联网科技同义词
巨龙之吼服务器部落多吗
有一个云服务器赚钱
数据库主键id标识如何设置
网络安全推动世界多极化发展
从数据库中读表
奇安信网络安全领导
网络安全服务器怎么用