1.4 Adding two or more widgets |
|
Written by kksou
|
|
Wednesday, 12 March 2008 |
Objective
Up until now, we have only added one widget to GtkWindow - either a label or a button. Suppose we want to add both the label and the button.
Overview
The GtkWindow widget is called a bin in php-gtk. A bin can contain one and only one child widget. To stuff more than one widgets in a GtkWindow, we need containers — widgets that can hold two or more widgets.
In this example, we will use a GtkVBox. As the name suggests, this is a vertical container that can be used to “pack” widgets vertically.
Sample Output

Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $vbox = new GtkVBox(); // note 1
$window->add($vbox); // note 2
$vbox->pack_start(new GtkLabel('Please click on the button: ')); // note 3
$button = new GtkButton("click me!"); $button->connect('clicked', 'on_click'); $vbox->pack_start($button); // note 4
$window->show_all();
|
- 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
- Create the vbox.
- Add the vbox to the GtkWindow.
- First stuff the label into the vbox.
- Followed by the button.
Note
|