7

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)
1
  • Do you have a .show_all() call in there somewhere? It's hard to troubleshoot problems from 3 line snippets. You're essentially asking someone to write a snippet you can drop in to your application for you. Jun 24, 2012 at 9:05

1 Answer 1

10
+50

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()
3
  • OK, Thanks, but how do I create the Notebook in Python?
    – njallam
    Jun 24, 2012 at 12:38
  • Add that part of the context to the question, and I'll provide an example with it. Jun 24, 2012 at 12:39
  • The problem on my side was the missing "window.show_all()"
    – njallam
    Jun 24, 2012 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .