[Python] 纯文本查看 复制代码
import tkinter,time
from tkinter import messagebox
top=tkinter.Tk()
top.title('倒计时')
sw=top.winfo_screenwidth()
sh=top.winfo_screenheight()
x=(sw-350)//2
y=(sh-50)//2
top.geometry('350x50+%d+%d' % (x, y))
Ib1=tkinter.Label(text='倒计时:',font=('楷体',14),height=2,width=10)
Ib1.grid(row=0,column=0)
ehour=tkinter.Entry(text=(''),font=('楷体',14),width=2)
ehour.insert('end','00')
ehour.grid(row=0,column=1)
Ihour=tkinter.Label(text='时',font=('楷体',14),height=2,width=1)
Ihour.grid(row=0,column=2)
emin=tkinter.Entry(text=(''),font=('楷体',14),width=2)
emin.insert('end','00')
emin.grid(row=0,column=3)
Imin=tkinter.Label(text='分',font=('楷体',14),height=2,width=1)
Imin.grid(row=0,column=4)
esec=tkinter.Entry(text=(''),font=('楷体',14),width=2)
esec.insert('end','00')
esec.grid(row=0,column=5)
Isec=tkinter.Label(text='秒',font=('楷体',14),height=2,width=1)
Isec.grid(row=0,column=6)
Ispace=tkinter.Label(text=(''),font=('楷体',14),height=2,width=3)
Ispace.grid(row=0,column=7)
def cal():
times=int(ehour.get())*3600+int(emin.get())*60+int(esec.get())
if times<=0:
messagebox.showinfo('错误提示','填写倒计时')
else:
while times>0:
times-=1
minute = times//60
second = times%60
hour=0
if minute>60:
hour=minute//60
minute=minute%60
ehour.delete(0,'end')
emin.delete(0,'end')
esec.delete(0,'end')
ehour.insert('end',hour)
emin.insert('end',minute)
esec.insert('end',second)
top.update()
time.sleep(1)
btn=tkinter.Button(text='开始',font=('楷体',14),height=1,width=4,command=cal)
btn.grid(row=0,column=8)
top.mainloop()