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

基于Python實現(xiàn)倒計時工具

 更新時間:2022年08月09日 12:58:17   作者:aguang5241  
這篇文章主要為大家詳細介紹了基于Python實現(xiàn)倒計時工具,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

基于Python編寫的倒計時工具,供大家參考,具體內(nèi)容如下

特點:

實時顯示當前時間
自動判斷用戶輸入日期,計算當前日期與目標日期相差大概多少年、月、日以及準確的相差天數(shù)

運行窗口

運行界面-1

運行界面-2

輸入日期-3

結(jié)果窗口-4

代碼

import time
import tkinter as tk
from tkinter import messagebox

def main():
? ? window1 = tk.Tk()
? ? window1.title('計時器【v0.0】')
? ? window1.geometry('300x200')

? ? l1 = tk.Label(window1, text = '當前時間:', font = ('宋體', 15))
? ? l1.place(x = 5, y = 10)
? ?
? ? def time_now():
? ? ? ? global seconds_now
? ? ? ? seconds_now = time.time()
? ? ? ? lt = time.localtime(seconds_now)
? ? ? ? time1 = []
? ? ? ? time2 = '%04d年%02d月%02d日 ? ?\n ? ?%02d時%02d分%02d秒' % (lt[0], lt[1], lt[2], lt[3], lt[4], lt[5])

? ? ? ? if time2 != time1:
? ? ? ? ? ? time1 = time2
? ? ? ? ? ? l1_2 = tk.Label(window1, text = time1, font = ('宋體', 20))
? ? ? ? ? ? l1_2.configure(text = time2)
? ? ? ? ? ? l1_2.place(x = 30, y = 50)
? ? ? ? ? ? l1_2.after(200, time_now)
? ? ? ? ? ??
? ? time_now()
? ??
? ? def input_time():
? ? ? ? window2 = tk.Tk()
? ? ? ? window2.title('計時器【v0.0】')
? ? ? ? window2.geometry('300x120')

? ? ? ? l2_1 = tk.Label(window2, text = '年', font = ('宋體', 15))
? ? ? ? l2_1.place(x = 90, y = 20)
? ? ? ? l2_2 = tk.Label(window2, text = '月', font = ('宋體', 15))
? ? ? ? l2_2.place(x = 170, y = 20)
? ? ? ? l2_3 = tk.Label(window2, text = '日', font = ('宋體', 15))
? ? ? ? l2_3.place(x = 250, y = 20)
? ? ? ? l2_4 = tk.Label(window2, text = '有效日期【1970/1/2-3001/1/1】', font = ('宋體', 10))
? ? ? ? l2_4.place(x = 50, y = 50)

? ? ? ? year = tk.Entry(window2, text = None, font = ('宋體', 15), width = 5)
? ? ? ? month = tk.Entry(window2, text = None, font = ('宋體', 15), width = 5)
? ? ? ? day = tk.Entry(window2, text = None, font = ('宋體', 15), width = 5)
? ? ? ? year.place(x = 40, y = 20)
? ? ? ? month.place(x = 120, y = 20)
? ? ? ? day.place(x = 200, y = 20)

? ? ? ? def get_time():
? ? ? ? ? ? try:
? ? ? ? ? ? ? ? y = int(year.get())
? ? ? ? ? ? ? ? m = int(month.get())
? ? ? ? ? ? ? ? d = int(day.get())
? ? ? ? ? ? ? ? lt_ = time.strptime(f'{y} {m} vvxyksv9kd', '%Y %m %d')
? ? ? ? ? ? ? ? seconds_get = time.mktime(lt_)
? ? ? ? ? ? except BaseException:
? ? ? ? ? ? ? ? tk.messagebox.showerror(message='輸入有誤!')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? window2.withdraw() ? ?
? ? ? ? ? ??
? ? ? ? ? ? string1 = '查詢?nèi)掌诰嚯x現(xiàn)在還有:'
? ? ? ? ? ? string2 = '查詢?nèi)掌诰嚯x現(xiàn)在已過去:'

? ? ? ? ? ? seconds_lasting = seconds_get - seconds_now
? ? ? ? ? ??
? ? ? ? ? ? day_lasting = abs(seconds_lasting) // 86400
? ? ? ? ? ? month_lasting = 0
? ? ? ? ? ? year_lasting = 0
? ? ? ? ? ? days = day_lasting
? ? ? ? ? ?
? ? ? ? ? ? if day_lasting > 356:
? ? ? ? ? ? ? ? year_lasting = day_lasting // 365
? ? ? ? ? ? ? ? day_lasting -= year_lasting * 365
? ? ? ? ? ? ? ? if day_lasting > 30:
? ? ? ? ? ? ? ? ? ? month_lasting = day_lasting // 30
? ? ? ? ? ? ? ? ? ? day_lasting -= month_lasting * 30
? ? ? ? ? ? elif day_lasting > 30:
? ? ? ? ? ? ? ? year_lasting = 0
? ? ? ? ? ? ? ? month_lasting = day_lasting // 30
? ? ? ? ? ? ? ? day_lasting -= month_lasting * 30?
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? year_lasting, month_lasting = 0, 0
? ? ? ? ? ??
? ? ? ? ? ? if seconds_lasting > 0:
? ? ? ? ? ? ? ? prompt = string1
? ? ? ? ? ? ? ? days += 1
? ? ? ? ? ? ? ? day_lasting += 1
? ? ? ? ? ? else:?
? ? ? ? ? ? ? ? prompt = string2 ?
? ? ? ? ? ? ? ? ??
? ? ? ? ? ? tk.messagebox.showinfo(message='%s%d天\n大概為%d年%d月%d天' % (prompt, days, year_lasting, month_lasting, day_lasting)) ??
? ? ? ? ? ? ? ??
? ? ? ? button2 = tk.Button(window2, text = '開始查詢', font = ('宋體', 15), command = get_time)
? ? ? ? button2.place(x = 110, y = 75)
? ? ? ?
? ? ? ? window2.mainloop()

? ? button1 = tk.Button(window1, text = '輸入查詢?nèi)掌?, font = ('宋體', 15), command = input_time)
? ? button1.place(x = 85, y = 125)

? ? window1.mainloop()

if __name__ == '__main__':
? ? main()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python jenkins 打包構(gòu)建代碼的示例代碼

    python jenkins 打包構(gòu)建代碼的示例代碼

    這篇文章主要介紹了python jenkins 打包構(gòu)建代碼的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2019-11-11
  • matlab繪制局部放大圖圖文教程

    matlab繪制局部放大圖圖文教程

    這篇文章主要給大家介紹了關(guān)于matlab繪制局部放大圖的相關(guān)資料,所謂局部放大即呈現(xiàn)子圖,以顯示局部細節(jié),需要的朋友可以參考下
    2023-07-07
  • Python open()文件處理使用介紹

    Python open()文件處理使用介紹

    這篇文章主要介紹了Python open()文件處理使用介紹,需要的朋友可以參考下
    2014-11-11
  • wxPython 入門教程

    wxPython 入門教程

    您可以在幾分鐘內(nèi)編寫一段 Python腳本和讓桌面擁有令人難以置信的相當漂亮的 GUI應(yīng)用程序。這篇文章向您展示如何使用一 Python-著稱的 GUI 庫wxPython,來做到這一點的。向您的朋友和鄰居介紹!
    2008-10-10
  • 將matplotlib繪圖嵌入pyqt的方法示例

    將matplotlib繪圖嵌入pyqt的方法示例

    這篇文章主要介紹了將matplotlib繪圖嵌入pyqt的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2020-01-01
  • Python中g(shù)lob類的使用方法

    Python中g(shù)lob類的使用方法

    Python內(nèi)置glob模塊是一個操作文件的相關(guān)模塊,由于模塊功能比較少,很容易掌握,這篇文章主要介紹了Python中g(shù)lob類的使用,需要的朋友可以參考下
    2022-12-12
  • python基礎(chǔ)教程之常用運算符

    python基礎(chǔ)教程之常用運算符

    這篇文章主要介紹了python基礎(chǔ)教程之常用運算符,包含數(shù)學(xué)運算符、用于判斷的運算符、邏輯運算符等,需要的朋友可以參考下
    2014-08-08
  • Python類的基本寫法與注釋風格介紹

    Python類的基本寫法與注釋風格介紹

    這篇文章主要介紹了Python類的基本寫法與注釋風格,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 四步教你學(xué)會打包一個新的Python模塊

    四步教你學(xué)會打包一個新的Python模塊

    當你安裝應(yīng)用程序時,通常是安裝一個軟件包,其中包含應(yīng)用程序的可執(zhí)行代碼和重要文件。在?Linux上,軟件一般被打包成RPM或DEB等格式,然而幾乎每天都有新的Python模塊發(fā)布,因此你很容易遇到一個尚未打包的Python模塊。本文教你四步打包一個新的Python模塊
    2022-09-09
  • 基于Python實現(xiàn)簡易學(xué)生信息管理系統(tǒng)

    基于Python實現(xiàn)簡易學(xué)生信息管理系統(tǒng)

    這篇文章主要為大家詳細介紹了python實現(xiàn)簡易學(xué)生信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07

最新評論