我正在努力获取一个 python/tkinter 标签小部件来更新其内容。根据今天早些时候的帖子,我按照说明如何将小部件放在一起。然而,在运行时,标签小部件不会更改内容,而只是保留其原始内容。据我所知,decrement_widget() 从来没有被调用过。有任何想法吗?
def snooze (secs):
"""
Snoozes for the given number of seconds. During the snooze, a progress
dialog is launched notifying the
"""
root = Tkinter.Tk()
prompt = 'hello'
label1 = Tkinter.Label(root, text=prompt, width=len(prompt))
label1.pack()
remaining = secs
def decrement_label ():
text = "Snoozing %d sec(s)" % remaining
remaining -= 1
label1.config(text=text, width=100)
label1.update_idletasks()
for i in range(1, secs + 1):
root.after(i * 1000, decrement_label )
root.after((i+1) * 1000, lambda : root.destroy())
root.mainloop()