GtkEntry Constructor

GtkEntry Constructor

GtkEntry (void);

Creates a widget that will hold a single line of text, either set programmatically through set_text() or entered by the user.

Example 15. Retrieving text from a GtkEntry widget

<?php

dl('php_gtk.'.(strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

/* set up a function to collect the input from the entry and print it */
function get_input($entry) {
  $input=$entry->get_text();
  echo "$input\n";
  $entry->grab_focus();
  $entry->set_text("");
}

/* set up the window */
$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_MOUSE);
$window->connect_object('destroy', array('gtk', 'main_quit'));

/* add a box container to the window to allow more than one child widget */
$box = &new GtkVBox();
$window->add($box);

/* add a GtkEntry to the box and connect it to the callback function */
$entry = &new GtkEntry();
$entry->connect('activate', 'get_input');
$box->add($entry);

/* add a GtkButton to the box and use connect_object() so that it
   will pass the GtkEntry to the callback when it is clicked */
$button = &new GtkButton('Return or click me to echo input');
$button->connect_object('clicked', 'get_input', $entry);
$box->add($button);

/* display everything and set the main loop running */
$box->show_all();
$window->show_all();
gtk::main();

?>

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.