我应该如何设置Gtk Notebook页面选项卡可扩展?

时间:2019-05-28 12:35:04

标签: python gtk gtk3

当我以编程方式将页面添加到Gtk.Notebook时,无法找到设置选项卡展开的方法。该属性在Glade中可用,所以我知道可以做到。这是一个使用reorderabledetachable属性的代码段。

#!/usr/bin/env python

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class GUI:
    def __init__(self):

        window = Gtk.Window()
        notebook = Gtk.Notebook()
        window.add(notebook)
        for i in range (4):
            label = Gtk.Label('label in page number ' + str(i))
            tab_label = Gtk.Label('page ' + str(i))
            notebook.append_page(label, tab_label)
            notebook.set_tab_detachable(label, True)
            notebook.set_tab_reorderable(label, True)
        window.show_all()
        window.connect('destroy', Gtk.main_quit)

app = GUI()
Gtk.main()

但是

notebook.set_tab_expandable(label, True)

失败

AttributeError: 'Notebook' object has no attribute 'set_tab_expandable'

1 个答案:

答案 0 :(得分:0)

解决方案是:

notebook.child_set_property(label, 'tab-expand', True)