Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)
share|improve this question
    
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. –  hbdgaf Jun 24 '12 at 9:05
add comment

1 Answer

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.