Suppose I have an interface like this consisting of GtkTextView and a button.

And I have code like this:
Code:
import pygtk
import gtk
class sample:
def __init__(self):
builder=gtk.Builder()
builder.add_from_file("sample.xml")
self.textview=builder.get_object("textview")
self.ok_button=builder.get_object("ok_button")
def on_ok(self,button,data=None):
print "Sample Message"
if __name__ == "__main__":
obj=sample()
gtk.main()
Here on_ok function is the handler for the button. Now what i want is that whenever the print statement is executed, i want it's output redirected to the textview. I know that I can use GtkTextBuffer and using set_buffer() I can achieve my objective. But i want the stdout to be redirected since I'm dealing with a proprietary library of python which sends all it's output to stdout.