#!/usr/bin/python

from gi.repository import Gtk

class Window(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect("destroy", Gtk.main_quit)
        self.set_title("Widgets")
        self.set_default_size(300, -1)
        self.widgetsInRow = {'0':1, '1':1}

        self.grid = Gtk.Grid()
        self.add(self.grid)

        button = Gtk.Button('Add button')
        button.connect('clicked', self.addWidget, Gtk.Button, 0)
        self.grid.attach(button, 0, 0, 1, 1)

        button = Gtk.Button('Add check button')
        button.connect('clicked', self.addWidget, Gtk.CheckButton, 1)
        self.grid.attach(button, 0, 1, 1, 1)

        self.show_all()

    def addWidget(self, pushedButton, widgetType, row):
        col = self.widgetsInRow.get('%s' % row)
        widget = widgetType('%s' % col)
        widget.show()
        self.grid.attach(widget,col, row, 1, 1)
        self.widgetsInRow['%s' % row] += 1

if __name__ == '__main__':
    window = Window()
    Gtk.main()
