Python – Grid container in GTK+ 3
Gtk.Grid is a container which arranges its child widgets in rows and columns, without the specification of the dimensions in the constructor. Children are added using
Gtk.Grid.attach(). They can span multiple rows or columns.
Gtk.Grid.attach()method takes five parameters:
left: the column number to attach the left side of
top: indicates the row number to attach the top side of
width: indicates the number of columns that the
height: indicates the number of rows that the
Adding a child next to existing child is also possible using
Gtk.Grid.attach_next_tomethod takes five parameters:
child:Gtk.Widget to add.
sibling: an existing
childwidget of a
Gtk.Gridor None. The child widget will be placed next to
Gtk.PositionTypeindicating the side of sibling.
width: indicate the number of columns the
childwidget will span.
height: indicate the number of rows the
childwidget will span
Follow below steps:
- import GTK+ 3 module.
- Create main window.
- Create button.
- Create grid.
Note: In IDE’s like Pycharm we can install a package named PyGObject in order to use GTK+ 3.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course