开化县传媒集团 方文涛 姚志卿 324300
再过百天,中国共产党就将迎来百年华诞。百年征程波澜壮阔,百年初心历久弥坚。为了迎接党的百年生日,集团领导打算在电子大屏宣传栏做一个建党百年倒计时牌。我决定用刚学的PYTHON做一个,找了一张图片做底图。直接上代码。
from tkinter import *
#import library
from tkinter import *
import time
from playsound import playsound
import datetime
from PIL import Image, ImageTk
root = Tk()
root.geometry("800x1200+1200+50") #界面大小和离屏距离
root.overrideredirect(0)
root.title("开化传媒集团建党百年倒计时牌")
root.lift()
root.wm_attributes("-topmost", True)
root.wm_attributes("-disabled", 0)
root.wm_attributes("-transparentcolor", "white")
root.resizable(0, 0)
photo = PhotoImage(file="jd100.png")
theLabel = Label(root,image=photo,compound = CENTER,fg = "white")
theLabel.pack()
jdbn=datetime.datetime(2021,7,1,0,0,0) #建党百年日期
today=datetime.datetime.now() #今天是几月几号
day=(jdbn-today).days #还有几天
d=str(day) #天数转字符串
seconds=(jdbn-today).seconds
def timer():
global seconds
if seconds > 0:
seconds=seconds-1
sec=seconds%60 #根据秒数得到还有几秒
minute=int(seconds/60%60) #根据秒得到分钟数
hour=int(seconds/60/60) #根据秒数得到小时
if hour>24:
hour=hour-24
m=str(minute)
s=str(sec)
h=str(hour)
time.set(h+'小时'+m+'分钟'+s+'秒')
timer_display.config(textvariable=time)
# call this function again in 1,000 milliseconds
root.after(1000, timer)
elif seconds == 0:
seconds.delete("1.0","end")
frames = Frame(root, width=600, height=100)
frames.pack()
time = StringVar()
timer_display = Label(root, font=('FZLTCXHJW.TTF', 30, 'bold'),fg="#FCE0B0", bg="#C10111")
timer_display.place(x=130, y=540)
days = Label(root, text=str(day),font=('FZLTCXHJW.TTF', 100),fg="#FCE0B0", bg="#C10111")
days.place(x=230, y=400)
timer() # start the timer
root.mainloop()
保存文件jdbn.py,运行测试成功。
运行打包命令:pyinstaller -F -w jdbn.py
运行测试结果: