PyGTK Box Class - PyGTK

What is PyGTK Box Class?

The gtk.Box class is an abstract class describing the functionality of a container in which widgets are located in a rectangular area. gtk.HBox and gtk.VBox widgets are resultant from it.

Child widgets in gtk.Hbox are arranged horizontally in the same row. On the other hand, child widgets of gtk.VBox are organized vertically in the same column.

gtk.Box class uses the following constructor –

The identical property is set to true by default. As an outcome, all child widgets are given equal allocation.

gtk.Box uses the packing tool to place child widgets in it with reference to a particular position, either with reference to start or end. pack_start() method places widgets from start to end. On the contrary, the pack_end() method puts widgets from end to start. Otherwise, you can use the add() method which is similar to pack_start().

The following methods are available for gtk.HBox as well as gtk.VBox −

  • gtk_box_pack_start ()
  • gtk_box_pack_end ()

gtk_box_pack_start ()

This method adds child to the box, packed with reference to the start of box –

The following are the parameters −
child − This is the widget object to be added to box
expand − This is set to True if child is to be given extra space in the box. Extra space is divided between all child widgets.
fill − If True, extra space will be allocated to child. Otherwise, this parameter is used as padding.
padding − This is the space in pixels between widgets in the box.
gtk_box_pack_end ()
This adds child to the box, packed with reference to the end of the box.

The resulting are the parameters −

  • child − This is the widget object to be added
  • expand − This is set to True if child is to be given extra space in the box. This extra space is divided between all child widgets.
  • fill − If True, extra space will be allocated to child otherwise used as padding.
  • padding − This is the space in pixels between the widgets in the box.

The function that sets the number of pixels to place between the children of the box is set_spacing (spacing)
The method add (widget) is inherited from the gtk.Container class. It adds widget to the container. This method can be used instead of the pack_start() method.

Example

In the instance specified below, the toplevel window covers a vertical box (gtk.VBox object box). It in turn has a VBox object vb and HBox object hb. In the upper box, a label, an entry widget and a button are located vertically. In the lower box, another set of label, entry and button are placed vertically.

Observe the resulting code –

The above code will produce the following output –

box_demo

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PyGTK Topics