如何从文本文件中读取文本框?

时间:2012-10-07 10:54:36

标签: python textbox stream text-files pygtk

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

1 个答案:

答案 0 :(得分: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)