Gtk.Notebook¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
|
the |
|
the |
|
the |
|
Emitted when the user or a function changes the current page. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.Notebook(**kwargs)¶
- Bases:
- Abstract:
No
GtkNotebook
is a container whose children are pages switched between using tabs.An example
Gtk.Notebook
There are many configuration options for
GtkNotebook
. Among other things, you can choose on which edge the tabs appear (see [method`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 [method`Gtk`.Notebook.set_scrollable]), and whether there will be a popup menu allowing the users to switch pages. (see [method`Gtk`.Notebook.popup_enable]).The
GtkNotebook
implementation of theGtkBuildable
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
GtkNotebook
:``xml <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> ``
- CSS nodes
`` notebook ├── header.top │ ├── [<action widget>] │ ├── tabs │ │ ├── [arrow] │ │ ├── tab │ │ │ ╰── <tab label> ┊ ┊ ┊ │ │ ├── tab[.reorderable-page] │ │ │ ╰── <tab label> │ │ ╰── [arrow] │ ╰── [<action widget>] │ ╰── stack
├── <child> ┊ ╰── <child>
GtkNotebook
has a main CSS node with namenotebook
, a subnode with nameheader
and below that a subnode with nametabs
which contains one subnode per tab with nametab
.If action widgets are present, their CSS nodes are placed next to the
tabs
node. If the notebook is scrollable, CSS nodes with namearrow
are placed as first and last child of thetabs
node.The main node gets the
.frame
style class when the notebook has a border (see [method`Gtk`.Notebook.set_show_border]).The header node gets one of the style class
.top
,.bottom
,.left
or.right
, depending on where the tabs are placed. For reorderable pages, the tab node gets the.reorderable-page
class.A
tab
node gets the.dnd
style class while it is moved with drag-and-drop.The nodes are always arranged from left-to-right, regardless of text direction.
- Accessibility
GtkNotebook
uses the following roles:Gtk.AccessibleRole.GROUP
for the notebook widgetGtk.AccessibleRole.TAB_LIST
for the list of tabsGtk.AccessibleRole.TAB
role for each tabGtk.AccessibleRole.TAB_PANEL
for each page
- classmethod new()[source]¶
- Returns:
the newly created
GtkNotebook
- Return type:
Creates a new
GtkNotebook
widget with no pages.
- append_page(child, tab_label)[source]¶
- Parameters:
child (
Gtk.Widget
) – theGtkWidget
to use as the contents of the pagetab_label (
Gtk.Widget
orNone
) – theGtkWidget
to be used as the label for the page, orNone
to use the default label, “page N”
- Returns:
the index (starting from 0) of the appended page in the notebook, or -1 if function fails
- Return type:
Appends a page to self.
- Parameters:
child (
Gtk.Widget
) – theGtkWidget
to use as the contents of the pagetab_label (
Gtk.Widget
orNone
) – theGtkWidget
to be used as the label for the page, orNone
to use the default label, “page N”menu_label (
Gtk.Widget
orNone
) – the widget to use as a label for the page-switch menu, if that is enabled. IfNone
, and tab_label is aGtkLabel
orNone
, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not aGtkLabel
, menu_label must be specified if the page-switch menu is to be used.
- Returns:
the index (starting from 0) of the appended page in the notebook, or -1 if function fails
- Return type:
Appends a page to self, specifying the widget to use as the label in the popup menu.
- detach_tab(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – a child
Removes the child from the notebook.
This function is very similar to [method`Gtk`.Notebook.remove_page], but additionally informs the notebook that the removal is happening as part of a tab DND operation, which should not be cancelled.
- get_action_widget(pack_type)[source]¶
- Parameters:
pack_type (
Gtk.PackType
) – pack type of the action widget to receive- Returns:
The action widget with the given pack_type or
None
when this action widget has not been set- Return type:
Gtk.Widget
orNone
Gets one of the action widgets.
See [method`Gtk`.Notebook.set_action_widget].
- get_current_page()[source]¶
- Returns:
the index (starting from 0) of the current page in the notebook. If the notebook has no pages, then -1 will be returned.
- Return type:
Returns the page number of the current page.
- Parameters:
child (
Gtk.Widget
) – a widget contained in a page of self- Returns:
the menu label, or
None
if the notebook page does not have a menu label other than the default (the tab label).- Return type:
Gtk.Widget
orNone
Retrieves the menu label widget of the page containing child.
- Parameters:
child (
Gtk.Widget
) – the child widget of a page of the notebook.- Returns:
the text of the tab label, or
None
if the widget does not have a menu label other than the default menu label, or the menu label widget is not aGtkLabel
. The string is owned by the widget and must not be freed.- Return type:
Retrieves the text of the menu label for the page containing child.
- get_n_pages()[source]¶
- Returns:
the number of pages in the notebook
- Return type:
Gets the number of pages in a notebook.
- get_nth_page(page_num)[source]¶
- Parameters:
page_num (
int
) – the index of a page in the notebook, or -1 to get the last page- Returns:
the child widget, or
None
if page_num is out of bounds- Return type:
Gtk.Widget
orNone
Returns the child widget contained in page number page_num.
- get_page(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – a child of self- Returns:
the
GtkNotebookPage
for child- Return type:
Returns the
GtkNotebookPage
for child.
- get_pages()[source]¶
- Returns:
a
GListModel
for the notebook’s children- Return type:
Returns a
GListModel
that contains the pages of the notebook.This can be used to keep an up-to-date view. The model also implements [iface`Gtk`.SelectionModel] and can be used to track and modify the visible page.
- get_tab_detachable(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – a childGtkWidget
- Returns:
True
if the tab is detachable.- Return type:
Returns whether the tab contents can be detached from self.
- get_tab_label(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – the page- Returns:
the tab label
- Return type:
Gtk.Widget
orNone
Returns the tab label widget for the page child.
None
is returned if child is not in self or if no tab label has specifically been set for child.
- get_tab_label_text(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – a widget contained in a page of self- Returns:
the text of the tab label, or
None
if the tab label widget is not aGtkLabel
. The string is owned by the widget and must not be freed.- Return type:
Retrieves the text of the tab label for the page containing child.
- get_tab_pos()[source]¶
- Returns:
the edge at which the tabs are drawn
- Return type:
Gets the edge at which the tabs are drawn.
- get_tab_reorderable(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – a childGtkWidget
- Returns:
True
if the tab is reorderable.- Return type:
Gets whether the tab can be reordered via drag and drop or not.
- insert_page(child, tab_label, position)[source]¶
- Parameters:
child (
Gtk.Widget
) – theGtkWidget
to use as the contents of the pagetab_label (
Gtk.Widget
orNone
) – theGtkWidget
to be used as the label for the page, orNone
to use the default label, “page N”position (
int
) – the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages
- Returns:
the index (starting from 0) of the inserted page in the notebook, or -1 if function fails
- Return type:
Insert a page into self at the given position.
- Parameters:
child (
Gtk.Widget
) – theGtkWidget
to use as the contents of the pagetab_label (
Gtk.Widget
orNone
) – theGtkWidget
to be used as the label for the page, orNone
to use the default label, “page N”menu_label (
Gtk.Widget
orNone
) – the widget to use as a label for the page-switch menu, if that is enabled. IfNone
, and tab_label is aGtkLabel
orNone
, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not aGtkLabel
, menu_label must be specified if the page-switch menu is to be used.position (
int
) – the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages.
- Returns:
the index (starting from 0) of the inserted page in the notebook
- Return type:
Insert a page into self at the given position, specifying the widget to use as the label in the popup menu.
- next_page()[source]¶
Switches to the next page.
Nothing happens if the current page is the last page.
- page_num(child)[source]¶
- Parameters:
child (
Gtk.Widget
) – aGtkWidget
- Returns:
the index of the page containing child, or -1 if child is not in the notebook
- Return type:
Finds the index of the page which contains the given child widget.
- popup_enable()[source]¶
Enables the popup menu.
If the user clicks with the right mouse button on the tab labels, a menu with all the pages will be popped up.
- prepend_page(child, tab_label)[source]¶
- Parameters:
child (
Gtk.Widget
) – theGtkWidget
to use as the contents of the pagetab_label (
Gtk.Widget
orNone
) – theGtkWidget
to be used as the label for the page, orNone
to use the default label, “page N”
- Returns:
the index (starting from 0) of the prepended page in the notebook, or -1 if function fails
- Return type:
Prepends a page to self.
- Parameters:
child (
Gtk.Widget
) – theGtkWidget
to use as the contents of the pagetab_label (
Gtk.Widget
orNone
) – theGtkWidget
to be used as the label for the page, orNone
to use the default label, “page N”menu_label (
Gtk.Widget
orNone
) – the widget to use as a label for the page-switch menu, if that is enabled. IfNone
, and tab_label is aGtkLabel
orNone
, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not aGtkLabel
, menu_label must be specified if the page-switch menu is to be used.
- Returns:
the index (starting from 0) of the prepended page in the notebook, or -1 if function fails
- Return type:
Prepends a page to self, specifying the widget to use as the label in the popup menu.
- prev_page()[source]¶
Switches to the previous page.
Nothing happens if the current page is the first page.
- remove_page(page_num)[source]¶
- Parameters:
page_num (
int
) – the index of a notebook page, starting from 0. If -1, the last page will be removed.
Removes a page from the notebook given its index in the notebook.
- reorder_child(child, position)[source]¶
- Parameters:
child (
Gtk.Widget
) – the child to moveposition (
int
) – the new position, or -1 to move to the end
Reorders the page containing child, so that it appears in position position.
If position is greater than or equal to the number of children in the list or negative, child will be moved to the end of the list.
- set_action_widget(widget, pack_type)[source]¶
- Parameters:
widget (
Gtk.Widget
) – aGtkWidget
pack_type (
Gtk.PackType
) – pack type of the action widget
Sets widget as one of the action widgets.
Depending on the pack type the widget will be placed before or after the tabs. You can use a
GtkBox
if you need to pack more than one widget on the same side.
- set_current_page(page_num)[source]¶
- Parameters:
page_num (
int
) – index of the page to switch to, starting from 0. If negative, the last page will be used. If greater than the number of pages in the notebook, nothing will be done.
Switches to the page number page_num.
Note that due to historical reasons,
Gtk.Notebook
refuses to switch to a page unless the child widget is visible. Therefore, it is recommended to show child widgets before adding them to a notebook.
- set_group_name(group_name)[source]¶
-
Sets a group name for self.
Notebooks with the same name will be able to exchange tabs via drag and drop. A notebook with a
None
group name will not be able to exchange tabs with any other notebook.
- Parameters:
child (
Gtk.Widget
) – the child widgetmenu_label (
Gtk.Widget
orNone
) – the menu label, orNone
for default
Changes the menu label for the page containing child.
- Parameters:
child (
Gtk.Widget
) – the child widgetmenu_text (
str
) – the label text
Creates a new label and sets it as the menu label of child.
- set_scrollable(scrollable)[source]¶
-
Sets whether the tab label area will have arrows for scrolling if there are too many tabs to fit in the area.
- set_show_border(show_border)[source]¶
-
Sets whether a bevel will be drawn around the notebook pages.
This only has a visual effect when the tabs are not shown.
- set_tab_detachable(child, detachable)[source]¶
- Parameters:
child (
Gtk.Widget
) – a childGtkWidget
detachable (
bool
) – whether the tab is detachable or not
Sets whether the tab can be detached from self to another notebook or widget.
Note that two notebooks must share a common group identifier (see [method`Gtk`.Notebook.set_group_name]) to allow automatic tabs interchange 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 drop destination and accept the target “GTK_NOTEBOOK_TAB”. The notebook will fill the selection with a
Gtk.Widget
pointing to the child widget that corresponds to the dropped tab.Note that you should use [method`Gtk`.Notebook.detach_tab] instead of [method`Gtk`.Notebook.remove_page] if you want to remove the tab from the source notebook as part of accepting a drop. Otherwise, the source notebook will think that the dragged tab was removed from underneath the ongoing drag operation, and will initiate a drag cancel animation.
```c static void on_drag_data_received (
Gtk.Widget
*widget,Gdk.Drop
*drop, GtkSelectionData *data,int
time,object
user_data) { GtkDrag *drag;Gtk.Widget
*notebook;Gtk.Widget
**child;drag = gtk_drop_get_drag (drop); notebook =
GObject.Object.get_data
(drag, “gtk-notebook-drag-origin”); child = (void*) gtk_selection_data_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.
- set_tab_label(child, tab_label)[source]¶
- Parameters:
child (
Gtk.Widget
) – the pagetab_label (
Gtk.Widget
orNone
) – the tab label widget to use, orNone
for default tab label
Changes the tab label for child.
If
None
is specified for tab_label, then the page will have the label “page N”.
- set_tab_label_text(child, tab_text)[source]¶
- Parameters:
child (
Gtk.Widget
) – the pagetab_text (
str
) – the label text
Creates a new label and sets it as the tab label for the page containing child.
- set_tab_pos(pos)[source]¶
- Parameters:
pos (
Gtk.PositionType
) – the edge to draw the tabs at
Sets the edge at which the tabs are drawn.
- set_tab_reorderable(child, reorderable)[source]¶
- Parameters:
child (
Gtk.Widget
) – a childGtkWidget
reorderable (
bool
) – whether the tab is reorderable or not
Sets whether the notebook tab can be reordered via drag and drop or not.
Signal Details¶
- Gtk.Notebook.signals.change_current_page(notebook, object)¶
- Signal Name:
change-current-page
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalobject (
int
) –
- Return type:
- Gtk.Notebook.signals.create_window(notebook, page)¶
- Signal Name:
create-window
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalpage (
Gtk.Widget
) – the tab of notebook that is being detached
- Returns:
a
GtkNotebook
that page should be added to- Return type:
Gtk.Notebook
orNone
The
::create-window
signal is emitted when a detachable tab is dropped on the root window.A handler for this signal can create a window containing a notebook where the tab will be attached. It is also responsible for moving/resizing the window and adding the necessary properties to the notebook (e.g. the
GtkNotebook
:group-name
).
- Gtk.Notebook.signals.focus_tab(notebook, object)¶
- Signal Name:
focus-tab
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalobject (
Gtk.NotebookTab
) –
- Return type:
- Gtk.Notebook.signals.move_focus_out(notebook, object)¶
- Signal Name:
move-focus-out
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalobject (
Gtk.DirectionType
) –
- Gtk.Notebook.signals.page_added(notebook, child, page_num)¶
- Signal Name:
page-added
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalchild (
Gtk.Widget
) – the childGtkWidget
affectedpage_num (
int
) – the new page number for child
the
::page-added
signal is emitted in the notebook right after a page is added to the notebook.
- Gtk.Notebook.signals.page_removed(notebook, child, page_num)¶
- Signal Name:
page-removed
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalchild (
Gtk.Widget
) – the childGtkWidget
affectedpage_num (
int
) – the child page number
the
::page-removed
signal is emitted in the notebook right after a page is removed from the notebook.
- Gtk.Notebook.signals.page_reordered(notebook, child, page_num)¶
- Signal Name:
page-reordered
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalchild (
Gtk.Widget
) – the childGtkWidget
affectedpage_num (
int
) – the new page number for child
the
::page-reordered
signal is emitted in the notebook right after a page has been reordered.
- Gtk.Notebook.signals.reorder_tab(notebook, object, p0)¶
- Signal Name:
reorder-tab
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalobject (
Gtk.DirectionType
) –p0 (
bool
) –
- Return type:
- Gtk.Notebook.signals.select_page(notebook, object)¶
- Signal Name:
select-page
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalobject (
bool
) –
- Return type:
- Gtk.Notebook.signals.switch_page(notebook, page, page_num)¶
- Signal Name:
switch-page
- Flags:
- Parameters:
notebook (
Gtk.Notebook
) – The object which received the signalpage (
Gtk.Widget
) – the new current pagepage_num (
int
) – the index of the page
Emitted when the user or a function changes the current page.
Property Details¶
- Gtk.Notebook.props.enable_popup¶
- Name:
enable-popup
- Type:
- Default Value:
- Flags:
If
True
, pressing the right mouse button on the notebook shows a page switching menu.
- Gtk.Notebook.props.group_name¶
- Name:
group-name
- Type:
- Default Value:
- Flags:
Group name for tab drag and drop.
- Gtk.Notebook.props.page¶
- Name:
page
- Type:
- Default Value:
-1
- Flags:
The index of the current page.
- Gtk.Notebook.props.pages¶
- Name:
pages
- Type:
- Default Value:
- Flags:
A selection model with the pages.
- Gtk.Notebook.props.scrollable¶
- Name:
scrollable
- Type:
- Default Value:
- Flags:
If
True
, scroll arrows are added if there are too many pages to fit.
- Gtk.Notebook.props.show_border¶
- Name:
show-border
- Type:
- Default Value:
- Flags:
Whether the border should be shown.
- Gtk.Notebook.props.show_tabs¶
- Name:
show-tabs
- Type:
- Default Value:
- Flags:
Whether tabs should be shown.
- Gtk.Notebook.props.tab_pos¶
- Name:
tab-pos
- Type:
- Default Value:
- Flags:
Which side of the notebook holds the tabs.