Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

关于tkinter after()的疑问

from tkinter import *
root = Tk()
def x():
    i = 0
    while i<100:
        i+=1
        print(i)
        root.after(1000,x)    
x()

倒数第二行中的root.after(1000,x),我理解的是1000毫秒后执行一次x函数,将其放入while循环中,预期结果应该是每间隔1000毫秒打印一个1。
可实际上却是先从1打印到99,然后弹出root窗口,等待1000毫秒后,不停地从1打印到99,中间也没有1000毫秒的间隔。这是为什么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你这是在玩递归,print(i) 将被运行 100**100(100的100次方) 次


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...