PyGTK For GUI Programming/Packing

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Packing is used to place the widgets in the application.

There are three types of packing.

  • Horizontal Box (HBox) - Horizontal row structure
  • Vertical Box (VBox) - Vertical row structure
  • Table/Grid (Table) - Table like structure

The format of the packing widgets is :

hbox = gtk.HBox(homogeneous, spacing)
vbox = gtk.VBox(homogeneous, spacing)
table = gtk.Table(rows, columns, homogeneous)

homogeneous (default=False) argument decides if the objects should all be the same size. HBox same width / VBox same height.
spacing (default=0) argument is the spacing between the different objects.

To place the widget inside the packing :

1. Create the packing object

box = gtk.HBox()

2. Add the widget to the box call the pack_start or pack_end method of the packing object

box.pack_start(widget, expand, fill, padding)
box.pack_end(widget, expand, fill, padding)

pack_start will start placing the widget from the start (left to right, top to bottom)
pack_end will start placing the widget from the end (right to left, bottom to top)

3. Show the box and widget

PyGTK For GUI Programming
 ← Input Widgets Packing