【发布时间】:2019-11-10 06:07:00
【问题描述】:
我正在尝试在同一个小部件上一个接一个地多次延迟打印(一个字符出现,几毫秒过去,然后下一个字符出现),类似于 >text 出现延迟 > 一秒钟过去> 更多文本出现延迟...等等。 time.sleep() 似乎不起作用,我不知道如何正确使用 .after()
这是我正在使用的代码
from tkinter import *
def insert_slow(widget, string):
if len(string) > 0:
widget.insert(END, string[0])
if len(string) > 1:
widget.after(50, insert_slow, widget, string[1:])
root=Tk()
tx=Text(root)
tx.pack()
insert_slow(tx, "this is a testing piece of text\n")
tx.after(3000)
loop=insert_slow(tx, "this is another testing piece of text")
root.mainloop()
【问题讨论】:
标签: user-interface tkinter textbox output python-3.7