November 2002
Intermediate to advanced
640 pages
16h 33m
English
You want to display more than one widget in a window.
Add all of the widgets in a container, and then add the container in the window:
// create the window
$window = &new GtkWindow();
// create the container - GtkVBox aligns widgets vertically
$container = &new GtkVBox();
// create a text entry widget and add it to the container
$text_entry = &new GtkEntry();
$container->pack_start($text_entry);
// create a button and add it to the container
$a_button = &new GtkButton('Abort');
$container->pack_start($a_button);
// create another button and add it to the container
$r_button = &new GtkButton('Retry');
$container->pack_start($r_button);
// create yet another button and add it to the container
$f_button = &new GtkButton('Fail');
$container->pack_start($f_button);
// add the container to the window
$window->add($container);
// display the window
$window->show_all();
// necessary so that the program exits properly
function shutdown() { gtk::main_quit(); }
$window->connect('destroy','shutdown');
// start GTK's signal handling loop
gtk::main();A window is a container that can hold only one widget. To put multiple widgets in a window, you must place all widgets into a container that can hold more than one widget and then put that container in the window. This process can be nested: the widgets inside a container can themselves be containers.
In the Solution, widgets are added to a
GtkVBox
container, which ...