PyGobject(五十一)布局容器之Notebook

Gtk.Notebook

Gtk.Notebook笔记本布局或者页式布局。是互相重叠的页面集合,每一页都包含不同的信息,且一次只有一个页面是可见的

StackSwitcher有点类似

继承关系

Gtk.Notebook是Gtk.Container的直接子类
这里写图片描述

Methods

方法修饰词方法名及参数
staticnew ()
append_page (child, tab_label)
append_page_menu (child, tab_label, menu_label)
detach_tab (child)
get_action_widget (pack_type)
get_current_page ()
get_group_name ()
get_menu_label (child)
get_menu_label_text (child)
get_n_pages ()
get_nth_page (page_num)
get_scrollable ()
get_show_border ()
get_show_tabs ()
get_tab_detachable (child)
get_tab_hborder ()
get_tab_label (child)
get_tab_label_text (child)
get_tab_pos ()
get_tab_reorderable (child)
get_tab_vborder ()
insert_page (child, tab_label, position)
insert_page_menu (child, tab_label, menu_label, position)
next_page ()
page_num (child)
popup_disable ()
popup_enable ()
prepend_page (child, tab_label)
prepend_page_menu (child, tab_label, menu_label)
prev_page ()
remove_page (page_num)
reorder_child (child, position)
set_action_widget (widget, pack_type)
set_current_page (page_num)
set_group_name (group_name)
set_menu_label (child, menu_label)
set_menu_label_text (child, menu_text)
set_scrollable (scrollable)
set_show_border (show_border)
set_show_tabs (show_tabs)
set_tab_detachable (child, detachable)
set_tab_label (child, tab_label)
set_tab_label_text (child, tab_text)
set_tab_pos (pos)
set_tab_reorderable (child, reorderable)

Virtual Methods

do_change_current_page (offset)
do_focus_tab (type)
do_insert_page (child, tab_label, menu_label, position)
do_move_focus_out (direction)
do_page_added (child, page_num)
do_page_removed (child, page_num)
do_page_reordered (child, page_num)
do_reorder_tab (direction, move_to_last)
do_select_page (move_focus)
do_switch_page (page, page_num)

Properties

NameTypeFlagsShort Description
enable-popupboolr/w/en如果为True,右键时弹出菜单可选择跳转到第几页
group-namestrr/w/enGroup name for tab drag and drop
pageintr/w/en当前页索引号
scrollableboolr/w/en如果为True,当页标签过多时,会显示滚动条
show-borderboolr/w/enWhether the border should be shown
show-tabsboolr/w/en是否显示页标签
tab-posGtk.PositionTyper/w/enWhich side of the notebook holds the tabs

Signals

NameShort Description
change-current-page
create-windowThe ::create-window signal is emitted when a detachable tab is dropped on the root window.
focus-tab
move-focus-out
page-addedthe ::page-added signal is emitted in the notebook right after a page is added to the notebook.
page-removedthe ::page-removed signal is emitted in the notebook right after a page is removed from the notebook.
page-reorderedthe ::page-reordered signal is emitted in the notebook right after a page has been reordered.
reorder-tab
select-page
switch-pageEmitted when the user or a function changes the current page.

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/14
# section 068

TITLE = "Notebook"
DESCRIPTION = """
The Gtk.Notebook widget is a Gtk.Container whose children are pages
that can be switched between using tab labels along one edge.
"""
import gi

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


class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Notebook Example")
        self.set_border_width(3)

        self.notebook = Gtk.Notebook()
        self.add(self.notebook)

        self.notebook.popup_enable()
        self.page1 = Gtk.Box()
        self.page1.set_border_width(10)
        self.page1.add(Gtk.Label('Default Page!'))
        self.notebook.append_page(self.page1, Gtk.Label('Plain Title'))

        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("help-about", Gtk.IconSize.MENU))


def main():
    win = MyWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()

代码解析

self.notebook = Gtk.Notebook()
self.add(self.notebook)

创建一个Gtk.Notebook,并添加到当前窗口

self.notebook.popup_enable()

设置右键可弹出菜单

self.page1 = Gtk.Box()
self.page1.set_border_width(10)
self.page1.add(Gtk.Label('Default Page!'))
self.notebook.append_page(self.page1, Gtk.Label('Plain Title'))

添加第一页,页标签为一个Gtk.Label

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("help-about", Gtk.IconSize.MENU))

添加第二页,页标签为一个Gtk.Image





代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值