Objective
Now that we’ve understood the expand parameter. Let's move on to the fill parameter.
Overview
- First create two GtkButton's.
- For the first button, set
expand=true and fill=true.
- For the second button, set
expand=true and fill=false.
Sample Output

Sample Code
1 2 3 4 5 6 7 8 9
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 240); $vbox = new GtkVBox(); $window->add($vbox);
$vbox->pack_start(new GtkButton('button1'), true, true); // note 1
$vbox->pack_start(new GtkButton('button2'), true, false); // note 2
|
- 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 both buttons, we set
expand=true. So as explained in the previous article, both will get equal share of the available spaces. For button 1, we set fill=true, meaning the button will fill up the entire space.
- For button 2, it will also get half the share of the space (because we set
expand=true). However, because we have set fill=false, it will NOT fill up the entire space, i.e. it will retain its default size.

|
 |
Compare the above with that of setting expand=true and fill=true as shown in the figure on the right.
See the difference?
|
Three Buttons – fill = on, off, on
|
In the example below, only button2 is expandable, but with fill=false. So we have button2 getting all the spaces, but retaining its original size:
1 2 3 4 5 6 7 8 9
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 240); $vbox = new GtkVBox(); $window->add($vbox);
$vbox->pack_start(new GtkButton('button1'), false, true); $vbox->pack_start(new GtkButton('button2'), true, 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.
|
 |

|
Two Buttons – both expand=off
|
Note that the parameter fill has meaning only when expand=true. When expand=false and you set fill=true, you won't be able to see any effect as shown below:
1 2 3 4 5 6 7 8 9
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 240); $vbox = new GtkVBox(); $window->add($vbox);
$vbox->pack_start(new GtkButton('button1'), false, true); $vbox->pack_start(new GtkButton('button2'), false, true);
|
- 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.
|
 |

|
Two Labels – appears to have no effect for Fill parameter
|
Setting the fill parameter to true or false does not seem to have any effect on GtkLabel. This is because a GtkLabel does not have a border like that of GtkButton. Hence it appears to have no effect. If we add a background color to the GtkLabel, we can see that it is working just as expected like the GtkButton.
1 2 3 4 5 6 7 8 9
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 240); $vbox = new GtkVBox(); $window->add($vbox);
$vbox->pack_start(new GtkLabel('label 1'), false, true); $vbox->pack_start(new GtkLabel('label 2'), true, true);
|
- 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.
|
 |

|
Note: If you run the above code, you will only see the following output. You will not see the blue background as shown below:

In case you’re wondering how to produce the blue background, here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 240); $vbox = new GtkVBox(); $window->add($vbox);
$eventbox1 = new GtkEventBox(); $eventbox1->add(new GtkLabel('label 1')); $eventbox1->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $vbox->pack_start($eventbox1, false, true);
$eventbox2 = new GtkEventBox(); $eventbox2->add(new GtkLabel('label 2'));
|
- 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.
Important Note
Once you have understood the expand and the fill parameters, you will find that you have now absolute control over the size, layout and positioning of widgets in php-gtk2![>
|