PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou




1.1 Hello World!
Written by kksou   
Wednesday, 12 March 2008

Objective

Let’s get started learning php-gtk2 with this simple yet complete "hello world!" script.

We will also understand the four key lines that constitute a standard php-gtk2 script. You will see these four lines in almost all the sample codes in this book.

Overview


Sample Output

1.1.gif

Sample Code

1   
2   
3   
4   
5   
6   
7   
<?php
$window = new GtkWindow(); // note 1
$window->connect_simple('destroy',array('Gtk','main_quit')); // note 2

// add your widgets here
$label = new GtkLabel("hello world!");
$window->add($label);
  • Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
  • Registration is free and immediate.
  • Have some doubt about the registration? Please read this forum article.

Explanation

For almost all php-gtk2 scripts, you will find the following four key lines (highlighted in blue):

  1. Creates a new window.
  2. Ensures a clean exit when you close the window. This basically says call Gtk::main_quit() when the user close the window.
  3. Displays all widgets that you have created, in this case, the window and the label.
  4. Let GTK take over and start waiting for events (e.g. mouse or keyboard input).

Note

  • These four lines form the simplest yet complete php-gtk2 script. For this “hello world” example, we simply stuff two more lines of code between these 4 lines:
  • $label = new GtkLabel("hello world!");
    $window->add($label);
    

    The first to create a new label, and the second to stuff the label inside the window.

  • You can also combine these two lines into one:
  • $window->add(new GtkLabel("hello world!"));
    


User reviews   Average user ratings:    5.0   (from 6 users)
  1. Indiana Gomez
    October 22, 2008 5:17am

  2. Nikkie Rutgers
    December 28, 2008 7:28pm

  3. Matias
    February 27, 2009 4:27am

  4. Ibn Saeed
    April 22, 2009 12:42pm

  5. lakshmikanth
    July 13, 2009 10:29pm

  6. raisun
    June 22, 2010 2:03am

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved