PyGTK Alignment Class - PyGTK

What is PyGTK Alignment Class?

This widget shows useful in regulatory alignment and size of its child widgets. It has four properties called xalign, yalign, xscale and yscale. The scale properties state how much of open space will be used by the child widgets. The align properties areused to place the child widget within available area.

All four properties take up a float value between 0 and 1.0. If xscale and yscale property is set to 0, it means that widget absorbs none of free space and if set to 1, widget absorbs maximum free space horizontally or vertically correspondingly.

The xalign and yalign property if set to 0, means that there will be no free space to the left or above widget. If set to 1, there will be maximum free space to left or above the widget.

The gtk.alignment class has the following constructor –


  • xalign − Is the fraction of the horizontal free space to the left of the child widget.
  • yalign − Is the fraction of vertical free space above the child widget.
  • xscale − Is is the fraction of horizontal free space that the child widget absorbs.
  • yscale − Is is the fraction of vertical free space that the child widget absorbs.


The resulting code proves the use of gtk.alignment widget. A Vbox in the toplevel window has an upper Vbox and lower Hbox placed in it. In the upper vertical box, a label and an Entry widget are located such that towards the left, 50% of space is kept free and more than 25% of this is occupied by assigning 0.5 xalign and 0.25 to yalign properties.

In the lower HBox, all the obtainable open space is on the left side. This is achieved by assigning 1 to xalign property. Hence, two buttons in the horizontal box appear right aligned.

The above code yields the resulting output –


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

PyGTK Topics