Sample Code 1: How to get started? |
|
Written by kksou
|
|
Tuesday, 12 September 2006 |
|
Problem How to get started in PHP-GTK2?
As with many other programming languages, let start with this simple yet complete "hello world!" PHP-GTK2 example as shown below:

Solution Do take some time to understand this simple yet complete "hello world!" PHP-GTK2 script.
Once you understand this script, you are on your way to picking up other widgets one by one and add onto this script.
Sample Code 1 2 3 4 5
| <?php $window = new GtkWindow(); $window->connect_simple('destroy', array('Gtk','main_quit')); $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
new GtkWindow() creates a new window.
connect('destroy', array('Gtk','main_quit')) ensures a clean exit when you close the window. This basically says call Gtk::main_quit() when the user close the window.
new GtkLabel("hello world!") creates the text string as label.
- And we use
$window->add to place the label in the window.
$window->show_all() shows the window and all its contents.
Gtk::main() - GTK takes over and starts waiting for events (e.g. mouse or keyboard input).
User reviews Average user ratings: 4.0 (from 37 users) Note: You have to be a registered member to leave a comment. Free registration here. |
March 01, 2008 9:52am
March 03, 2008 4:19pm
March 24, 2008 5:07pm
April 02, 2008 12:15am
April 03, 2008 9:32am
April 29, 2008 1:01am
May 03, 2008 3:20am
May 12, 2008 7:31am
June 02, 2008 10:11pm
June 17, 2008 8:54am
July 09, 2008 7:14pm
July 10, 2008 10:52am
July 22, 2008 2:21am
August 06, 2008 2:36pm
August 26, 2008 9:47pm
October 07, 2008 4:48am
October 14, 2008 1:21am
October 20, 2008 2:21am
October 22, 2008 1:49am
October 23, 2008 1:47pm
November 05, 2008 11:59pm
February 12, 2009 4:54am
February 13, 2009 9:09pm
March 06, 2009 2:47pm
March 12, 2009 1:29am
April 13, 2009 5:55am
April 22, 2009 11:34am
June 02, 2009 2:24am
June 23, 2009 7:37am
June 28, 2009 12:48am
Unknown
August 05, 2009 9:53am
November 09, 2009 5:33am
good
January 21, 2010 11:58pm
April 19, 2010 6:21am
May 23, 2010 10:41pm
Class 'GtkWindow' not found
June 21, 2010 8:07pm
August 05, 2010 11:23pm
This is a very good file!