GtkEntry Constructor

GtkEntry ([ string text [, int max ]]);

Creates a widget that will hold a single line of text. You have the freedom to either set the widget programatically through set_text() or have it entered by the user.

If text is given, it will be set as the default value for the widget. If max is given, it will be set as the maximum allowed length of the widget's text value in characters.

Example 59. Retrieving text and echoing it using GtkEntry

//Function to retrieve text from GtkEntry and print it
function get_input($entry) {
    $input = $entry->get_text();
    echo "$input\r\n";

//Setting up the Window
// Note the usage of connect_simple()
// instead of deprecated connect_object()
$window = new GtkWindow();
$window->connect_simple('destroy', array('Gtk', 'main_quit'));

//Adding a box to the Window to allow more than one Child
$box = new GtkVBox();

//Adding the GtkEntry widget and connecting
// it to the callback function: get_text()
$entry = new GtkEntry();
$entry->connect('activate', 'get_input');

//Adding a GtkButton to the box and use connect_simple()
// so that it will pass the GtkEntry to the callback
// function when it is clicked
$button = new GtkButton('Click Me to echo input!');
$button->connect_simple('clicked', 'get_input', $entry);

//Display everything and start the main loop