Gtk.Notebook


Gtk.Notebook — A tabbed notebook container

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Notebook

See also:

Gtk.Container


Functions:


Signals:

  • “change-current-page” (notebook, user_data)
  • “create-window” (notebook, page, x, y, user_data)
  • “focus-tab” (notebook, user_data)
  • “move-focus-out” (notebook, user_data)
  • “page-added” (notebook, child, page_num, user_data)
  • “page-removed” (notebook, child, page_num, user_data)
  • “page-reordered” (notebook, child, page_num, user_data)
  • “reorder-tab” (notebook, user_data)
  • “select-page” (notebook, user_data)

Description:

The GtkNotebook widget is a Gtk.Container whose children are pages that can be switched between using tab labels along one edge.

There are many configuration options for Gtk.Notebook. Among other things, you can choose on which edge the tabs appear (see Gtk.Notebook::set_tab_pos()), whether, if there are too many tabs to fit the notebook should be made bigger or scrolling arrows added (see Gtk.Notebook::set_scrollable()), and whether there will be a popup menu allowing the users to switch pages.

(see Gtk.Notebook::popup_enable(), Gtk.Notebook::popup_disable())

GtkNotebook as Gtk.Buildable:

The GtkNotebook implementation of the Gtk.Buildable interface supports placing children into tabs by specifying tab as the type attribute of a <child> element. Note that the content of the tab must be created before the tab can be filled.

A tab child can be specified without specifying a <child> type attribute.

To add a child widget in the notebooks action area, specify "action-start" or action-end as the type attribute of the <child> element.

An example of a UI definition fragment with Gtk.Notebook:

<object class="GtkNotebook">
  <child>
    <object class="GtkLabel" id="notebook-content">
      <property name="label">Content</property>
    </object>
  </child>
  <child type="tab">
    <object class="GtkLabel" id="notebook-tab">
      <property name="label">Tab</property>
    </object>
  </child>
</object>

Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.Notebook widget with no pages.

  • Returns: the newly created Gtk.Notebook

append_page()

append_page (self, child:Gtk.Widget, tab_label:Gtk.Widget=None) -> int

Appends a page to notebook.

  • Returns: the index (starting from 0) of the appendedpage in the notebook, or -1 if function fails

append_page_menu()

append_page_menu (self, child:Gtk.Widget, tab_label:Gtk.Widget=None, menu_label:Gtk.Widget=None) -> int

Appends a page to notebook, specifying the widget to use as thelabel in the popup menu.

  • Returns: the index (starting from 0) of the appendedpage in the notebook, or -1 if function fails

prepend_page()

prepend_page (self, child:Gtk.Widget, tab_label:Gtk.Widget=None) -> int

Prepends a page to notebook.

  • Returns: the index (starting from 0) of the prependedpage in the notebook, or -1 if function fails

prepend_page_menu()

prepend_page_menu (self, child:Gtk.Widget, tab_label:Gtk.Widget=None, menu_label:Gtk.Widget=None) -> int

Prepends a page to notebook, specifying the widget to use as thelabel in the popup menu.

  • Returns: the index (starting from 0) of the prependedpage in the notebook, or -1 if function fails

insert_page()

insert_page (self, child:Gtk.Widget, tab_label:Gtk.Widget=None, position:int) -> int

Insert a page into notebook at the given position.

  • Returns: the index (starting from 0) of the insertedpage in the notebook, or -1 if function fails

insert_page_menu()

insert_page_menu (self, child:Gtk.Widget, tab_label:Gtk.Widget=None, menu_label:Gtk.Widget=None, position:int) -> int

Insert a page into notebook at the given position, specifyingthe widget to use as the label in the popup menu.

  • Returns: the index (starting from 0) of the insertedpage in the notebook

remove_page()

remove_page (self, page_num:int)

Removes a page from the notebook given its indexin the notebook.


detach_tab()

detach_tab (self, child:Gtk.Widget)

Removes the child from the notebook. This function is very similar to `Gtk.Container:remove()`,but additionally informs the notebook that the removalis happening as part of a tab DND operation, which shouldnot be cancelled.

  • Since: 3.16

page_num()

page_num (self, child:Gtk.Widget) -> int

Finds the index of the page which contains the given childwidget.

  • Returns: the index of the page containing child, or-1 if childis not in the notebook

next_page()

next_page (self)

Switches to the next page. Nothing happens if the current page isthe last page.


prev_page()

prev_page (self)

Switches to the previous page. Nothing happens if the current pageis the first page.


reorder_child()

reorder_child (self, child:Gtk.Widget, position:int)

Reorders the page containing child, so that it appears in positionposition. If position is greater than or equal to the number ofchildren in the list or negative, child will be moved to the endof the list.


set_tab_pos()

set_tab_pos (self, pos:Gtk.PositionType)

Sets the edge at which the tabs for switching pages in thenotebook are drawn.


set_show_tabs()

set_show_tabs (self, show_tabs:bool)

Sets whether to show the tabs for the notebook or not.


set_show_border()

set_show_border (self, show_border:bool)

Sets whether a bevel will be drawn around the notebook pages.This only has a visual effect when the tabs are not shown.See Gtk.Notebook:set_show_tabs().


set_scrollable()

set_scrollable (self, scrollable:bool)

Sets whether the tab label area will have arrows forscrolling if there are too many tabs to fit in the area.


popup_enable()

popup_enable (self)

Enables the popup menu: if the user clicks with the rightmouse button on the tab labels, a menu with all the pageswill be popped up.


popup_disable()

popup_disable (self)

Disables the popup menu.


get_current_page()

get_current_page (self) -> int

Returns the page number of the current page.

  • Returns: the index (starting from 0) of the currentpage in the notebook. If the notebook has no pages,then -1 will be returned.

get_menu_label()

get_menu_label (self, child:Gtk.Widget) -> Gtk.Widget

Retrieves the menu label widget of the page containing child.

  • Returns: the menu label, or None if thenotebook page does not have a menu label other than thedefault (the tab label).

get_nth_page()

get_nth_page (self, page_num:int) -> Gtk.Widget

Returns the child widget contained in page number page_num.

  • Returns: the child widget, or Noneif page_numis out of bounds.

get_n_pages()

get_n_pages (self) -> int

Gets the number of pages in a notebook.

  • Returns: the number of pages in the notebook

  • Since: 2.2


get_tab_label()

get_tab_label (self, child:Gtk.Widget) -> Gtk.Widget

Returns the tab label widget for the page child.None is returned if child is not in notebook orif no tab label has specifically been set for child.

  • Returns: the tab label.

set_menu_label()

set_menu_label (self, child:Gtk.Widget, menu_label:Gtk.Widget=None)

Changes the menu label for the page containing child.


set_menu_label_text()

set_menu_label_text (self, child:Gtk.Widget, menu_text:str)

Creates a new label and sets it as the menu label of child.


set_tab_label()

set_tab_label (self, child:Gtk.Widget, tab_label:Gtk.Widget=None)

Changes the tab label for child.If None is specified for tab_label, then the page willhave the label “page N”.


set_tab_label_text()

set_tab_label_text (self, child:Gtk.Widget, tab_text:str)

Creates a new label and sets it as the tab label for the pagecontaining child.


set_tab_reorderable()

set_tab_reorderable (self, child:Gtk.Widget, reorderable:bool)

Sets whether the notebook tab can be reorderedvia drag and drop or not.

  • Since: 2.10

set_tab_detachable()

set_tab_detachable (self, child:Gtk.Widget, detachable:bool)

Sets whether the tab can be detached from notebook to anothernotebook or widget. Note that 2 notebooks must share a common group identificator(see Gtk.Notebook:set_group_name()) to allow automatic tabsinterchange between them. If you want a widget to interact with a notebook through DnD(i.e.: accept dragged tabs from it) it must be set as a dropdestination and accept the target “GTK_NOTEBOOK_TAB”. The notebookwill fill the selection with a Gtk.Widget`**` pointing to the childwidget that corresponds to the dropped tab. Note that you should use `Gtk.Notebook:detach_tab()` insteadofGtk.Container:remove() if you want to remove the tab fromthe source notebook as part of accepting a drop. Otherwise,the source notebook will think that the dragged tab wasremoved from underneath the ongoing drag operation, andwill initiate a drag cancel animation. static void on_drag_data_received (Gtk.Widget widget, GdkDragContext context, gint x, gint y, Gtk.SelectionData data, guint info, guint time, gpointer user_data) { Gtk.Widget notebook; Gtk.Widget *child; notebook = Gtk.Drag:get_source_widget (context); child = (void) Gtk.SelectionData:get_data (data); process_widget (child); Gtk.Notebook:detach_tab (GTK_NOTEBOOK (notebook), child); } If you want a notebook to accept drags from other widgets,you will have to set your own DnD code to do it.

  • Since: 2.10

get_menu_label_text()

get_menu_label_text (self, child:Gtk.Widget) -> str

Retrieves the text of the menu label for the page containingchild.

  • Returns: the text of the tab label, or None if thewidget does not have a menu label other than the defaultmenu label, or the menu label widget is not a Gtk.Label.The string is owned by the widget and must not be freed.

get_scrollable()

get_scrollable (self) -> bool

Returns whether the tab label area has arrows for scrolling.See Gtk.Notebook:set_scrollable().

  • Returns: True if arrows for scrolling are present

get_show_border()

get_show_border (self) -> bool

Returns whether a bevel will be drawn around the notebook pages.See Gtk.Notebook:set_show_border().

  • Returns: True if the bevel is drawn

get_show_tabs()

get_show_tabs (self) -> bool

Returns whether the tabs of the notebook are shown.See Gtk.Notebook:set_show_tabs().

  • Returns: True if the tabs are shown

get_tab_label_text()

get_tab_label_text (self, child:Gtk.Widget) -> str

Retrieves the text of the tab label for the page containingchild.

  • Returns: the text of the tab label, or None if thetab label widget is not a Gtk.Label. The string is ownedby the widget and must not be freed.

get_tab_pos()

get_tab_pos (self) -> Gtk.PositionType

Gets the edge at which the tabs for switching pages in thenotebook are drawn.

  • Returns: the edge at which the tabs are drawn

get_tab_reorderable()

get_tab_reorderable (self, child:Gtk.Widget) -> bool

Gets whether the tab can be reordered via drag and drop or not.

  • Returns: True if the tab is reorderable.

  • Since: 2.10


get_tab_detachable()

get_tab_detachable (self, child:Gtk.Widget) -> bool

Returns whether the tab contents can be detached from notebook.

  • Returns: True if the tab is detachable.

  • Since: 2.10


get_tab_hborder()

get_tab_hborder (self) -> int

Gtk.Notebook:get_tab_hborder has been deprecated since version 3.4 and should not be used in newly-written code. this function returns zero Returns the horizontal width of a tab border.

  • Returns: horizontal width of a tab border

  • Since: 2.22


get_tab_vborder()

get_tab_vborder (self) -> int

Gtk.Notebook:get_tab_vborder has been deprecated since version 3.4 and should not be used in newly-written code. this function returns zero Returns the vertical width of a tab border.

  • Returns: vertical width of a tab border

  • Since: 2.22


set_current_page()

set_current_page (self, page_num:int)

Switches to the page number page_num. Note that due to historical reasons, Gtk.Notebook refusesto switch to a page unless the child widget is visible.Therefore, it is recommended to show child widgets beforeadding them to a notebook.


set_group_name()

set_group_name (self, group_name:str=None)

Sets a group name for notebook. Notebooks with the same name will be able to exchange tabsvia drag and drop. A notebook with a None group name willnot be able to exchange tabs with any other notebook.

  • Since: 2.24

get_group_name()

get_group_name (self) -> str

Gets the current group name for notebook.

  • Returns: the group name,or None if none is set.

  • Since: 2.24


set_action_widget()

set_action_widget (self, widget:Gtk.Widget, pack_type:Gtk.PackType)

Sets widget as one of the action widgets. Depending on the pack typethe widget will be placed before or after the tabs. You can usea Gtk.Box if you need to pack more than one widget on the same side. Note that action widgets are “internal” children of the notebook and thusnot included in the list returned from `Gtk.Container:foreach()`.

  • Since: 2.20

get_action_widget()

get_action_widget (self, pack_type:Gtk.PackType) -> Gtk.Widget

Gets one of the action widgets. See Gtk.Notebook:set_action_widget().

  • Returns: The action widget with the given pack_typeor None when this action widget has not been set.

  • Since: 2.20


Example:

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

class Notebook(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title('Notebook')
        self.set_default_size(300, 200)
        self.connect('destroy', Gtk.main_quit)

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

        for page in range(1, 4):
            label1 = Gtk.Label('Notebook')
            label2 = Gtk.Label()
            label2.set_text('Page %i' % (page))
            notebook.append_page(label1, label2)
            notebook.set_tab_reorderable(label1, True)

window = Notebook()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""