PHPBuilder - Getting Started with PHP-GTK: Part 1 Page 3

RSS Twitter

Getting Started with PHP-GTK: Part 1 - Page 3

by: Ray Hunter
August 26, 2004

GTK Window
When you run this code you should get a window similar to this one (however, your window decoration will most likely be different than mine).
Let's run through this code and pick it apart. Skip down to the window comment and let's begin there. Here we are going to create the main GTK window. We will create the window object first with the following statement:

= &new GtkWindow();
This provides the main window where we can add widgets, too. Once we have the main window we can start modifing the window's attributes by calling specific methods of the GtkWindow class. Here is a link to the PHP-GTK reference documentation for the GtkWindow class: It's a good idea to bookmark the reference documentation if you are going to be using PHP-GTK.

$window->set_title("Simple Example");
You will notice that we are using only three of the methods on the GtkWindow object. One thing that I want to point out before we move forward is that these Objects follow a heirarchial order. As such, they also inherit the parent functions. You will notice that in the reference documentation there is a small section entitled "Object Heirarchy" that displays the heirarchy of the class.
The set_default_size method allows you to set a default width and height for the window when it is first created. The function takes two parameters that are width and height in terms of pixels.
The set_border_width method is a method from the GtkContainer class. The set_border_width method is used to create and set a border that goes around the container which will surround the button.
set_title does what its name implies, which is to set the title of the window. Here, the title of the window is set to "Simple Example".
The connect method, from GtkObject, allows the developer to connect a user defined function to a signal. Additional information that can be sent as additional arguments are passed to the method. Check out GtkObject::connect for a complete review of the method. With the connect method you can associate the "destroy" signal with a gtk function called "main_quit". You can check out additional GTK functions on PHP-GTK site under "GTK Functions".
With these method calls we have set up the size, title, container width, and associated a user function with a specific signal. Next, let's add a button with a tooltip on it along with a function associated with the action of clicking it.

« Previous Page
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Ray Hunter



(Maximum characters: 1200). You have characters left.