
This tutorial is part of a series of PHP-GTK tutorials. For a full list of tutorials, see this thread.
In order to display a text box on a GTK+ application, you need to make use of the GtkTextView class. A GtkTextView is used to be able to display a large portion of text in a text box on your GTK+ application window. If you are wondering as to how to make text scroll after it spans longer than the size of the GtkTextView (which is also relative to the bounds of the container it may be in and the size of the GtkWindow), you can make use of a GtkScrolledWindow. The GtkTextView actually added to the GtkScrolledWindow, and then the GtkScrolledWindow is packed into the container which is then subsequently added to the GtkWindow. An example of using a GtkScrolledWindow is like follows:
PHP Code:
$gtkScrolledWindow = new GtkScrolledWindow();
$gtkScrolledWindow->add($textView);
$gtkScrolledWindow->set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC);
$init_vbox->pack_start($gtkScrolledWindow);
Going back onto the purpose of this tutorial, in order to fetch the current text within a GtkTextView, you need to fetch the current contents of the buffer. In most instances, you'd be fetching the text from the GtkTextView when an event is fired - perhaps as a result of a GtkButton press. To fetch the contents of the GtkTextView:
PHP Code:
$get_buffer = $this->textView->get_buffer();
$get_text = $get_buffer->get_text($get_buffer->get_start_iter(), $get_buffer->get_end_iter());
And that's it. If you intend to save the contents of the buffer to a file, you can then save the contents of $get_text to a file using the file_put_contents() function, and of course, fetch the contents of a file and put it into a GtkTextView using the file_get_contents() function in PHP.
I would recommend you make extensive use of the PHP-GTK and PyGTK documentation for help while developing your PHP-GTK applications. In some areas, the PyGTK documentation is more elaborative than many areas of the PHP-GTK documentation - so make use of both. You can also check the documentation on gtk.org.