【发布时间】:2016-03-05 21:30:45
【问题描述】:
我目前正在开发一个项目,该项目需要非常简单的倒数计时器,可以在 tkinter GUI 中运行,并且不依赖于递归。我尝试了不同的方法,但到目前为止似乎没有任何效果。
import time
from tkinter import *
root = Tk()
root.title("Timer")
root.geometry("100x100")
def countdown(count):
label = Label(root, text= count)
label.place(x=35, y=15)
for i in range(5,0,-1):
countdown(i)
time.sleep(1)
root.mainloop()
【问题讨论】:
-
sleep将使窗口锁定。尝试使用root.after。
标签: python timer tkinter countdown