【问题标题】:How to refresh a Tk inter window with new data from a string如何使用字符串中的新数据刷新 Tkinter 窗口
【发布时间】:2016-03-22 07:28:24
【问题描述】:
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()

【问题讨论】:

  • 什么新数据?只是随机的、虚构的数据?从文件中读取数据?一个过程?服务器?数据库?

标签: python tkinter refresh


【解决方案1】:

请阅读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()

【讨论】:

  • 这正是我想要的。非常感谢,圣诞快乐!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-29
  • 1970-01-01
  • 2017-04-24
  • 2020-04-14
  • 2012-07-01
  • 2014-01-27
  • 1970-01-01
相关资源
最近更新 更多