我想知道一种读取文本文件并将其内容添加到文本框中的方法。我在tkinter中做这件事,所以我需要用Python获取文本,并使用tkinter将其放入文本框中,这将非常好。提前感谢!
您将使用with
和open
打开文件,然后使用Text.insert
将其内容放入文本框中。
以下是基本演示:
from Tkinter import Text, Tk
r = Tk()
t = Text()
t.grid()
with open("/path/to/file") as myfile:
t.insert("1.0", myfile.read())
r.mainloop()