HomePHP Page 5 - Programming with PHP and GTK, Part 1
Widgets - PHP
Have you ever thought of writing a PHP application for client side execution without having a web server present? Learn the basics of creating a front end for PHP using PHP-GTK.
Widgets are data structures which house information about a user-interface objects. This in simple terms mean user-interface objects like buttons, text boxes, windows and combo-boxes.
So let's see how we can create such widgets. To house these widgets, you'll need to create a GTK container. This container can be either vertical (GtkVBox) or horizontal (GtkHBox). In GtkHBox, all the widgets will align horizontally, while it will align vertically in the case of GtkVbox. We'll create a vertical container for our program.
// Add a GtkVBox class to our window $box = &new GtkVBox(); $window->add($box);
Let's add a text entry widget to this box:
// Add a GtkEntry class to our window $entry = &new GtkEntry(); $entry->set_text("Play with Strings"); $box->pack_start($entry);
The above code creates a new GtkEntry widget, sets the text in the field to "Play with Strings" and adds it to the box. The code $box->pack_start($entry); is used to add the entry to the already created box. You can skip the $entry->set_text("Play with Strings") if you do not want to initialize the text and want a blank entry field.
Now let's add a button:
// Add a GtkButton class to our window $button = &new GtkButton("Buttontext"); $button->connect("clicked", "buttonfunction"); $box->pack_start($button);
This button which is created will have the text "Buttontext" on it. When the button is clicked, the function "buttonfunction" will be called to handle the click. Now how about a tool tip when the mouse hovers over the button?
You can set the Tooltips delay using $tt->set_delay(200) where 200 is amount of delay after which the tooltips will be displayed. You can set tool tips for each widget separately.