Forum und email

GtkEntry Конструктор

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.

Пример 57. Retrieving text and echoing it using GtkEntry

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

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

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

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

//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);
$box->add($button);

//Display everything and start the main loop
$window->show_all();
Gtk::main();
?>