Avatar ·

Sleep 和 while True 在 tkinter 中

📁 讨论, 苏维埃, Python 版本讨论:Python 3.x 最新动态, 新手

例如有以下代码:

def tk_sleep():
    status_send = Tk()
    status_send.geometry('400x340')
    tx_1 = Text(status_send, font=('times', 12), width=62, height=15, wrap=WORD)
    tx_1.pack()
    for i in range(10):
        tx_1.insert(1.0, 'hello world')
        tx_1.update()
        sleep(5)

此时整个包含 widget 的窗口会卡住。如何避免这种情况?