使用python和ttkbootstrap工具实现放假倒计时

使用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实现中考倒计时

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值