我制作了这段代码。我需要每秒更新一次,但我不能像时钟一样使用.after(1000,func)
like.after(1000,func)。我无法使用time.sleep(1)
。我不知道还能做什么。请帮我解决这个问题。
import tkinter
from datetime import datetime
agora = datetime.now()
encontro = datetime.strptime('03/08/2016/13', "%d/%m/%Y/%H")
delta = encontro - agora
n_dias = delta.days
n_horas = int(delta.seconds/3600)
n_min = int((delta.seconds - n_horas*3600)/60)
n_seg = int(delta.seconds - n_horas*3600 - n_min*60)
texto1 = tkinter.Label()
texto1['text'] = "Quanto tempo para ver minha lindinha:"
texto1['font'] = "Times 8 bold"
texto1.pack()
dias = tkinter.Label()
dias['font'] = "Times 8 bold"
horas = tkinter.Label()
horas['font'] = "Times 8 bold"
minutos = tkinter.Label()
minutos['font'] = "Times 8 bold"
e = tkinter.Label()
e['font'] = "Times 8 bold"
e['text'] = 'e'
segundos = tkinter.Label()
segundos['font'] = "Times 8 bold"
if n_dias!=1:
dias['text'] = n_dias,"Dias"
else: dias['text'] = n_dias,"Dia"
if n_horas!=1:
horas['text'] = n_horas,"Horas"
else: horas['text'] = n_horas,"Hora"
if n_min!=1:
minutos['text'] = n_min,"minutos"
else: minutos['text'] = n_min,"minuto"
if n_seg!=1:
segundos['text'] = n_seg,"segundos"
else: segundos['text'] = n_seg,"segundo"
dias.pack(side="left")
horas.pack(side="left")
minutos.pack(side="left")
e.pack(side="left")
segundos.pack(side="left")
谢谢。 我需要写更多内容来发布它 - '