How do I add a Notebook to a Box in a VBox?

I have created an empty box in Glade to add a Notebook to. The reason I am not adding the actual Notebook in Glade is because I hear that you cannot add pages to a Notebook made in Glade.

So, in Glade I have created a Box in an empty slot in a VBox. The code I am running is:

self.box = self.builder.get_object("box")

self.subjects = Gtk.Notebook()
self.box.add(self.subjects)

Nothing happens upon running, except these warnings which I believe will just occur anyway:

/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `Window' can't be set after construction
Gtk.Window.__init__(self, type=type, **kwds)
/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `NotetakerWindow' can't be set after construction
Gtk.Window.__init__(self, type=type, **kwds)

Solution 1:

Here's an example that has context

from gi.repository import Gtk

class Handler:
    def onDeleteWindow(self, *args):
        Gtk.main_quit(*args)

    def addNotebookClick(self, *args):
        vbox = builder.get_object("attachtome")
        mynote = builder.get_object("notebook1")
        temp = Gtk.Box()
        mynote.reparent(temp)
        vbox.pack_start(temp, expand=False, fill=False, padding=0)
        window.show_all()

builder = Gtk.Builder()
builder.add_from_file("howtoaskaprogrammingquestion.glade")
builder.connect_signals(Handler())
window = builder.get_object("window1")
window.show_all()

Gtk.main()

It works with this glade file

It provides this functionality: enter image description here

This also works, if you're using your own Notebook. Note that when you run the example you see a slight change in window geometry(the object being added), but it doesn't appear to render because it doesn't have any tabs yet.

from gi.repository import Gtk
class Handler:
    def onDeleteWindow(self, *args):
        Gtk.main_quit(*args)

    def addNotebookClick(self, *args):
        vbox = builder.get_object("attachtome")
        mynote = Gtk.Notebook()
        #mynote = builder.get_object("notebook1")
        #temp = Gtk.Box()
        #mynote.reparent(temp)
        vbox.pack_start(mynote, expand=False, fill=False, padding=0)
        window.show_all()

builder = Gtk.Builder()
builder.add_from_file("howtoaskaprogrammingquestion.glade")
builder.connect_signals(Handler())
window = builder.get_object("window1")
window.show_all()

Gtk.main()