想要做一个倒计时用窗口显示,如何让窗口的文本动态刷新呢?
其他问答
1
from tkinter import*
from datetime import datetime
a=0
someday=datetime(2022,1,15,00,00,00)
def timea(date):
today=datetime.now()
to=someday-today
return to
win=Tk()
win.geometry("620x60")
win.title("倒计时")
time=Label(win,text=timea(someday),font=('华文行楷',40),fg='red',width=23,height=1 )
time.grid(row=10,column=1)
win.resizable(0,0)
win.mainloop()
这样运行只是静止的。
怎么让它能够动态刷新呢?
-
from tkinter import* from datetime import datetime a=0 someday=datetime(2022,1,15,00,00,00) def timea(date): today=datetime.now().replace(microsecond=0) to=someday-today return to win=Tk() win.geometry("620x60") win.title("倒计时") time=Label(win,text=timea(someday),font=('华文行楷',40),fg='red',width=23,height=1 ) time.grid(row=10,column=1) def changetime(): time.config(text = timea(someday) ) win.after(1000,changetime) win.after(1000, changetime) win.resizable(0,0) win.mainloop()
-
要想做多一些功能, 用wxpython 吧。 参考下这个。
发表回复