How can I print (for example in a label) t开发者_开发百科he text into a GtkTextView? For GtkLabel and GtkEntry there are gtk_label_get_text() and gtk_entry_get_text(), but for GtkTextView?
Based on doublep's answer, for quick copy/paste:
char *get_text_of_textview(GtkWidget *text_view) {
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer((GtkTextView *)text_view);
gchar *text;
gtk_text_buffer_get_bounds(buffer, &start, &end);
text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
return text;
}
You can:
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
gchar *text;
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
Don't forget to g_free (text)
when no longer needed.
Just for you people from Google, this is the way it's done in python:
def getText(textview):
buffer = textview.get_buffer()
startIter, endIter = buffer.get_bounds()
text = buffer.get_text(startIter, endIter, False)
return text
精彩评论