如何在pygtk的左侧对齐笔记本栏?

时间:2017-02-10 12:17:20

标签: python-3.x pygtk gtk3

我在将左侧的笔记本栏对齐,在pygtk

的默认顶部时遇到问题
# starting with notebook  from here
        self.notebook = Gtk.Notebook()
        self.add(self.notebook)
        self.page1 = Gtk.Box()
        self.page1.set_border_width(10)
        self.notebook.append_page(self.page1, Gtk.Label('page 1'))
        self.page1.add(Gtk.Label('Nvidia'))

        self.page2 = Gtk.Box()
        self.page2.set_border_width(10)
        self.page2.add(Gtk.Label('A page with an image for a Title.'))
        #self.notebook.append_page(self.page2,Gtk.Image.new_from_icon_name("wifi",Gtk.IconSize.MENU))
        self.notebook.append_page(self.page2,Gtk.Label('Wifi'))

如何在笔记本页面上有一个图标和一个标签

1 个答案:

答案 0 :(得分:1)

以下是解决这两个问题的示例:

#!/usr/bin/env python3
from gi.repository import Gtk


class Window(Gtk.Window):
    def __init__(self):
        super().__init__()
        self.connect('delete-event', Gtk.main_quit)

        content = Gtk.Label(label='Page content')

        label_box = Gtk.HBox()
        label_box.pack_start(
            Gtk.Image.new_from_icon_name('text-x-generic', 1),
            False, False, 5)
        label_box.pack_start(Gtk.Label(label='Page 1'), True, True, 0)
        label_box.show_all()

        notebook = Gtk.Notebook()
        notebook.append_page(content, label_box)
        notebook.set_tab_pos(Gtk.PositionType.LEFT)

        self.add(notebook)
        self.show_all()


if __name__ == '__main__':
    Window()
    Gtk.main()