2012-10-07 47 views
1

我想知道一种阅读文本文件并将其内容添加到文本框的方法。我在PyGTK中这样做,所以我需要使用Python获取文本,并使用PyGTK将它放入文本框中,那将很棒。提前致谢!如何从文本文件读入文本框?

回答

2

假设你的文本框是一个TextView

#read the contents of the file 
text = open("yourfile").read() 
#get the underlying TextBuffer object of the TextView and set its text 
textbox.get_buffer().set_text(text)