PDA

View Full Version : pygtk: access text in a textview


Ubuntuud
November 29th, 2006, 03:30 PM
Hi,
I'm creating a program with pygtk.
It's my first serious one. But I'm running into some problems with textview. I have the following code.

sw = gtk.ScrolledWindow();
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC);
textview = gtk.TextView();
sw.add(textview);

Now I would like to access the text in the textview to save it.
And to open saved files.
How can I do that? I think I have to do something with textbuffers, but I don't know what.

Could anyone give an example? Thanks in advance!

bradleyd
November 29th, 2006, 04:03 PM
you can look here http://www.moeraki.com/pygtktutorial/pygtk2tutorial/ch-TextViewWidget.html
there is a textview example.

ohgod
November 29th, 2006, 04:50 PM
I believe textview widgets have get_text() and set_text() functions to manipulate the text in the widget.

Ubuntuud
November 30th, 2006, 02:29 AM
OK. Thanks to the both of you!

moephan
November 30th, 2006, 01:01 PM
You'll notice in the tutorial that to manipulate text in a textview, you get the textbuffer for the textview:

buffer = textview.get_buffer()

and then you can do all sorts of stuff, particularly deleting and inserting text, etc...

buffer.insert_at_cursor(text)

Cheers, Rick