Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I made something, so after clicking a button, some text should appear in the TextView. Part of my code:

def on_button1_clicked(self, builer):
        self.writetest = self.builder.get_object("textview1")
        self.writetest.insert_at_cursor("something")

Unfortunately, when I click the button I get:

AttributeError: 'TextView' object has no attribute 'insert_at_cursor'

According to GTK Documentation there is such attribute: http://developer.gnome.org/gtk3/stable/GtkTextView.html#GtkTextView-insert-at-cursor

I have the same problem with Entry as well, if I change TextView to Entry. But if I use set_text instead of insert_at_cursor in my code, it works.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The method you are looking for is not on TextView, but on TextBuffer. So you need to do:

buffer = self.writetest.get_buffer()
buffer.insert_at_cursor('Hello World!')

The documentation link you gave does not point to a method, but rather to a signal. Signals cannot be directly called.

share|improve this answer
    
Thanks for the answer! I thought signals could be used as methods. –  mivoligo Jun 29 '12 at 18:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.