我正在编写一个函数,应该每隔0.2秒将一个字符放入tkinter Text小部件中。 不幸的是,当我运行这个函数时,程序会立即为每个字符挂起,然后插入整个字符串而不是正常迭代。
def put(win, text):
#win is a tkinter Text object
#text is a string of text
#split text to an array of characters
output = list(text)
for i in range(len(output)):
sleep(0.2)
win.insert(END, output[i], )
编辑:这也不起作用,结果是相同的
def put(win, text):
#win is a tkinter TExt object
#text is a string of text
for char in text:
win.after(200, win.insert(END, char))
编辑2:这只是挂起
def put(win, text):
#win is a tkinter TExt object
#text is a string of text
def place(win, char):
win.insert(END, char)
for char in text:
win.after(200,lambda: put(win, 'z'))