2.8 Have 3 buttons of size 60x36 at top left-hand corner |
|
Written by kksou
|
|
Tuesday, 25 March 2008 |
Objective
Suppose now you want the button to be exactly of the size 96 x 36.
Overview
The concept is exactly the same as explained in the previous article. Instead of one button, we just continuously add three buttons using a for-next loop, each time packing the button into the hbox with expand set to false.
Sample Output

Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(400, 100); $vbox = new GtkVBox(); $window->add($vbox);
$hbox = new GtkHBox(); for ($i=1; $i<=3; ++$i) { $button = new GtkButton('button'.$i); $button->set_size_request(60,32); // note 1
$button->connect('clicked', 'on_click'); // note 2
$hbox->pack_start($button, false); // note 3
$hbox->pack_start(new GtkLabel(), false); // note 4
}
$vbox->pack_start($hbox, false);
|
- 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
- Set the size of the button.
- Set up the event handler for the button. We will explain in details about this in the chapter Events Handling.
- Stuff the button in hbox with
expand=false.
- This adds a little gap between the buttons. Try commenting out this line. You will get the following with all the button 'stacked' together.

- Get the label of the button and echo it on the command window. We will explain in details about this in the chapter Events Handling.
|