|
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

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):
- Creates a new window.
- Ensures a clean exit when you close the window. This basically says call
Gtk::main_quit() when the user close the window.
- Displays all widgets that you have created, in this case, the window and the label.
- 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 There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |
|