使用python和ttkbootstrap工具实现放假倒计时,精确到秒
import time
import datetime
from tkinter import messagebox
import ttkbootstrap as ttk
root = ttk.Window(title="放假倒计时", themename="litera", size=(550, 350), position=(700, 100), resizable=None)
def clock():
exam_time = datetime.datetime(2024, 2, 5, 21, 20, 0)
now = datetime.datetime.now()
lctime = time.localtime()
lctimee = time.strftime("%Y-%m-%d", lctime)
target = exam_time - now
days = target.days
secs = target.seconds
hours = secs // 3600
secs = secs % 3600
mins = secs // 60
secs = secs % 60
root.after(1000, clock)
tt = ttk.Label(root, text="今天是" + str(lctimee), font=("仿宋", 24), bootstyle="dark")
tt.grid(row=0, column=1)
t = ttk.Label(root, text="放假倒计时:" + str(days) + "天" + str(hours) + "时" + str(mins) + "分" + str(secs) + "秒", font=("华文琥珀", 24), bootstyle="warning")
t.grid(row=1, column=1)
hh = ttk.Label(root, text="加油", font=("楷体", 30), bootstyle="info")
hh.grid(row=2, column=1)
h = ttk.Label(root, text="坚持", font=("楷体", 30), bootstyle="info")
h.grid(row=3, column=1)
h1 = ttk.Label(root, text="必胜", font=("楷体", 30), bootstyle="info")
h1.grid(row=4, column=1)
h2 = ttk.Label(root, text="你最棒", font=("楷体", 30), bootstyle="info")
h2.grid(row=5, column=1)
def quitty():
messagebox.showinfo("放假倒计时", "放假yyds")
time.sleep(1)
root.quit()
btn2 = ttk.Button(root, text='知道了', bootstyle="primary", command=quitty)
btn2.grid(row=6, column=1)
clock()
root.mainloop()
把GUI打包放在桌面也不错哦,pycharm终端输入:
pyinstaller -F -w test.py
在dist文件夹下就可以看到打包好的小程序啦
参考:python实现中考倒计时