相关疑难解决方法(0)

制作python/tkinter标签小部件更新?

我正在努力获取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()
Run Code Online (Sandbox Code Playgroud)

python tkinter

18
推荐指数
2
解决办法
8万
查看次数

标签 统计

python ×1

tkinter ×1