Tkinter的Text如何实时显示insert的内容?

 

Python code


from tkinter import *
import time

def onGo():        
        for i in range(50):
                t.insert(END,'a_'+str(i))
                time.sleep(1)
                
root = Tk()
t = Text(root)
t.pack()
goBtn = Button(text = "Go!",command = onGo)
goBtn.pack()
root.mainloop()



Tkinter的Text如何实时显示insert的内容?_第1张图片

点击Go按钮后,一个数字一个数字的实时弹出来。。
而不是处理完毕后一下子都出来了。。

from tkinter import *
  
def onGo():        
    def counter(i):        
        if i > 0:
            t.insert(END,'a_'+str(i))
            t.after(1000, counter, i-1)
        else:
            goBtn.config(state=NORMAL)
 
     
    goBtn.config(state=DISABLED)
    counter(50)
                  
root = Tk()
t = Text(root)
t.pack()
goBtn = Button(text = "Go!",command = onGo)
goBtn.pack()
root.mainloop()
from Tkinter import *
import time
 
def onGo():        
        for i in range(50):
                t.insert(END,'a_'+str(i))
                time.sleep(0.1)
                t.update()
                 
root = Tk()
t = Text(root)
t.pack()
goBtn = Button(text = "Go!",command = onGo)
goBtn.pack()
root.mainloop()

 

你可能感兴趣的:(Python杂记)