如何使用字符串中的新数据刷新 Tk inter window

How to refresh a Tk inter window with new data from a string

root = Tk()
prompt = (string)
label1 = Label(root.attributes("-topmost", True), text=prompt, width=(50), height=(25))
label1.pack()

def close_after_1s():
    root.destroy()

root.after(1000, close_after_1s)
root.mainloop()

请阅读 this help page 以及其他一些内容。

也许以下内容会有所帮助。小部件选项可以在创建后通过下标设置,如下所示,或者使用例如 label.config(text=next(strit)).

import tkinter as tk  # 3.x
root = tk.Tk()
strings = ['First', 'Second', 'Third', 'Last', 'Closing']
strit = iter(strings)
label = tk.Label(root, text=next(strit), width=(50), height=(25))
label.pack()

def refresh():
    try:
        label['text'] = next(strit)
        root.after(1000, refresh)
    except StopIteration:
        root.destroy()

root.after(1000, refresh)
root.mainloop()