PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



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

1.4.gif

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

  1. Create the vbox.
  2. Add the vbox to the GtkWindow.
  3. First stuff the label into the vbox.
  4. Followed by the button.

Note



User reviews

There are no user reviews yet.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved