2012-10-07 69 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)