我在 Glade 中创建了一个空框,用于添加笔记本。我没有在 Glade 中添加实际的笔记本,因为我听说您无法向在 Glade 中创建的笔记本添加页面。
因此,在 Glade 中,我在 VBox 的一个空槽中创建了一个 Box。我正在运行的代码是:
self.box = self.builder.get_object("box")
self.subjects = Gtk.Notebook()
self.box.add(self.subjects)
运行时什么也不会发生,除了这些我相信无论如何都会发生的警告:
/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
这是一个有上下文的例子
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()
它提供了此功能:
如果您使用自己的 Notebook,此方法同样有效。请注意,当您运行示例时,您会看到窗口几何形状(正在添加的对象)略有变化,但它似乎并未呈现,因为它还没有任何选项卡。
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()