next up previous contents
Next: Advanced data manipulation Up: Using GTK Previous: Signals and Call-backs   Contents

Widgets

The general steps to create a widget in the GTK are:

What is unique to GTK, widgets could be grouped together and then packed into container widgets. It solves the problem with hard-coded dimensions and coordinates of widgets.

Most packing is done by boxes. These are invisible widget containers that we can pack our widgets into which come in two forms, a horizontal box, and a vertical box. When packing widgets into a horizontal box, the objects are inserted horizontally from left to right or right to left depending on the call used. In a vertical box, widgets are packed from top to bottom or vice versa. You may use any combination of boxes inside or beside other boxes to create the desired effect.

To create a new horizontal box, we use a call to gtk_hbox_new(), and for vertical boxes, gtk_vbox_new(). The gtk_box_pack_start() and gtk_box_pack_end() functions are used to place objects inside of these containers. The gtk_box_pack_start() function will start at the top and work its way down in a vbox, and pack left to right in an hbox. gtk_box_pack_end() will do the opposite, packing from bottom to top in a vbox, and right to left in an hbox. Using these functions allow us to right justify or left justify our widgets and may be mixed in any way to achieve the desired effect. An object may be another container or a widget. In fact, many widgets are actually containers themselves, including the button, but we usually only use a label inside a button.

By using these calls, GTK knows where you want to place your widgets so it can do automatic resizing and other nifty things. There's also a number of options as to how your widgets should be packed. As one can imagine, this method gives us quite a bit of flexibility when placing and creating widgets.

The gtk_widget_show() lets GTK know that we are done setting the attributes of the widget, and it is ready to be displayed. One may also use the gtk_widget_hide to make it disappear again.

GTK widgets include:

There are many more widgets but this isn't the main goal of this thesis to describe them all, further information can be found in [9,10,11] and on the GTK Web page www.gtk.org.


next up previous contents
Next: Advanced data manipulation Up: Using GTK Previous: Signals and Call-backs   Contents
Igor Wojnicki 2001-02-21