欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于python寫個(gè)國(guó)慶假期倒計(jì)時(shí)程序

 更新時(shí)間:2021年09月30日 10:58:54   作者:易小俠  
國(guó)慶假期快到了,想查查還有幾天幾小時(shí)到假期,這對(duì)程序員小菜一碟,輕輕松松用python寫個(gè)倒計(jì)時(shí)程序(天、時(shí)、分、秒),助你熬到假期

        國(guó)慶假期快到了,想查查還有幾天幾小時(shí)到假期,這對(duì)程序員小菜一碟,輕輕松松用python寫個(gè)倒計(jì)時(shí)程序(天、時(shí)、分、秒),助你熬到假期!

一、先看效果:

 二、安裝python:

1、下載安裝python

下載安裝python3.9.6,進(jìn)入python官方網(wǎng)站:http://www.python.org/

 點(diǎn)擊Python 3.9.6

直接安裝即可。

2、驗(yàn)證安裝成功。

按win+R輸入cmd,打開控制臺(tái),輸入python -V,輸出python版本號(hào)說(shuō)明安裝成功。

三、代碼

##import library
from tkinter import *
import time
from datetime import datetime,timedelta
 
################GUI to display window ##########################
root = Tk()
root.geometry('450x300')
root.resizable(0,0)
root.config(bg ='blanched almond')
root.title('國(guó)慶倒計(jì)時(shí)')
Label(root, text = '國(guó)慶倒計(jì)時(shí)' , font = 'arial 20 bold', bg ='papaya whip').pack()
 
############GUI to display current time#######################
Label(root, font ='arial 15 bold', text = ' 當(dāng)前時(shí)間:', bg = 'papaya whip').place(x = 40 ,y = 70)
 
#######################GUI to set the future time ##########
Label(root, font ='arial 15 bold', text = ' 到達(dá)時(shí)間:', bg = 'papaya whip').place(x = 40 ,y = 110)
#set year
year_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 month
month_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 day
day_set= StringVar()
Entry(root, textvariable =day_set, width =2, font = 'arial 12').place(x=275, y=115)
day_set.set('00')
 
# set hour
hour_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 min
min_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 sec
sec_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 = ' 倒計(jì)時(shí):', bg ='papaya whip').place(x = 40 ,y = 150)
#storing seconds
sec = 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 minutes
mins= 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 hours
hrs= StringVar()
Entry(root, textvariable = hrs, width =2, font = 'arial 12').place(x=225, y=155)
Label(root, font ='arial 15', text = '時(shí)', bg = 'papaya whip').place(x = 250 ,y = 150)
hrs.set('00')
 
# storing days
days= 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()

四、運(yùn)行

打開工程文件,在地址欄里輸入cmd,按Enter回車,即打開控制臺(tái)。

 輸入python main.py,按回車就打開了程序GUI界面。

 到達(dá)時(shí)間填2021年10月1日,按start按鈕,就開始放假倒計(jì)時(shí)啦!

相關(guān)資源:基于python的假期倒計(jì)時(shí)(天、時(shí)、分、秒).zip

到此這篇關(guān)于用python寫個(gè)國(guó)慶假期倒計(jì)時(shí)程序的文章就介紹到這了,更多相關(guān)python倒計(jì)時(shí)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 用python給csv里的數(shù)據(jù)排序的具體代碼

    用python給csv里的數(shù)據(jù)排序的具體代碼

    在本文里小編給大家分享的是關(guān)于用python給csv里的數(shù)據(jù)排序的具體代碼內(nèi)容,需要的朋友們可以學(xué)習(xí)下。
    2020-07-07
  • 如何基于Python實(shí)現(xiàn)word文檔重新排版

    如何基于Python實(shí)現(xiàn)word文檔重新排版

    這篇文章主要介紹了如何基于Python實(shí)現(xiàn)word文檔重新排版,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • python如何提取xml指定內(nèi)容

    python如何提取xml指定內(nèi)容

    這篇文章主要介紹了python如何提取xml指定內(nèi)容,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • Python PyCryptodome庫(kù)介紹與實(shí)例教程

    Python PyCryptodome庫(kù)介紹與實(shí)例教程

    PyCryptodome提供了豐富的加密功能,可以滿足多種安全需求,本文介紹了幾個(gè)常見的使用場(chǎng)景,包括對(duì)稱加密、非對(duì)稱加密、哈希函數(shù)和消息認(rèn)證碼,感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • 詳解OpenCV自適應(yīng)直方圖均衡化的應(yīng)用

    詳解OpenCV自適應(yīng)直方圖均衡化的應(yīng)用

    在本文中,將介紹如何應(yīng)用對(duì)比度受限的自適應(yīng)直方圖均衡化 ( Contrast Limited Adaptive Histogram Equalization, CLAHE ) 來(lái)均衡圖像,需要的可以參考一下
    2022-02-02
  • pytest?用例執(zhí)行失敗后其他不再執(zhí)行

    pytest?用例執(zhí)行失敗后其他不再執(zhí)行

    本文主要介紹了pytest?用例執(zhí)行失敗后其他不再執(zhí)行,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • python使用tqdm模塊處理文件閱讀進(jìn)度條顯示

    python使用tqdm模塊處理文件閱讀進(jìn)度條顯示

    這篇文章主要為大家介紹了python使用tqdm模塊處理文件閱讀顯示進(jìn)度條示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • django 模型字段設(shè)置默認(rèn)值代碼

    django 模型字段設(shè)置默認(rèn)值代碼

    這篇文章主要介紹了django 模型字段設(shè)置默認(rèn)值代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • python的open函數(shù)使用案例代碼

    python的open函數(shù)使用案例代碼

    python打開文件使用open()函數(shù),返回一個(gè)指向文件的指針,在python中使用open函數(shù)對(duì)文件進(jìn)行處理,這篇文章主要介紹了python中的open函數(shù)使用,需要的朋友可以參考下
    2023-02-02
  • Python操作Excel神器openpyxl使用教程(超詳細(xì)!)

    Python操作Excel神器openpyxl使用教程(超詳細(xì)!)

    openpyxl庫(kù)是一個(gè)很好處理xlsx的python庫(kù),下面這篇文章主要給大家介紹了關(guān)于Python辦公自動(dòng)化openpyxl使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01

最新評(píng)論