Home arrow PHP arrow 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.

  1. Programming with PHP and GTK, Part 1
  2. Installing PHP-GTK
  3. A Test Run
  4. A PHP-GTK Window
  5. Widgets
  6. A Simple Program
By: Vinu Thomas
Rating: starstarstarstarstar / 40
August 16, 2004

print this article



Widgets in GTK

What are widgets?

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();

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");

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");

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?

$tt = &new GtkTooltips();
$tt->set_tip($widget, 'Here's a Tip', '');

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.

>>> More PHP Articles          >>> More By Vinu Thomas

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: