我的程序 window 没有响应。为什么 idk?

my program window is not responding .why idk?

    
    import psutil
    import time
    from tkinter import *
    def eventc(event):
        while True :
            print(psutil.cpu_stats())
            time.sleep(2)
    
    def closewin(event):
        exit(0)
    
    def myevent(event):
        print('okayy')
    window=Tk()
    #button for stats
    btn=Button(window, text="click me for cpu stats", fg='blue')
    btn.place(x=80, y=100)
    btn.bind('<Button>',eventc)
    #btn for closing the window
    winclose=Button(window, text="close window", fg='blue')
    winclose.place(x=95, y=0)
    winclose.bind('<Button>',closewin)
    #for window
    window.title('my \'so called first app\'')
    window.geometry("300x200+10+10")
    window.mainloop()

当我点击 get cpu stats 时,我得到了统计数据,但 window 之后不会响应。 在强行结束 window 之后,它给我这个退出 code:Process 完成,退出代码为 -805306369 (0xCFFFFFFF) 你能帮我看看为什么吗

eventc() 内的 while 循环将阻止 tkinter mainloop 处理未决事件和更新。建议用.after()代替while循环:

def eventc(event=None):
    print(psutil.cpu_stats())
    window.after(2000, eventc) # execute eventc() 2000ms later