Gtk.Notebook¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/en |
If |
||
r/w/en |
Group name for tab drag and drop |
||
r/w/en |
The index of the current page |
||
r/w/en |
If |
||
r/w/en |
Whether the border should be shown |
||
r/w/en |
Whether tabs should be shown |
||
r/w/en |
Which side of the notebook holds the tabs |
Child Properties¶
Name |
Type |
Default |
Flags |
Short Description |
|---|---|---|---|---|
|
r/w |
Whether the tab is detachable |
||
|
r/w |
The string displayed in the child’s menu entry |
||
|
|
r/w |
The index of the child in the parent |
|
|
r/w |
Whether the tab is reorderable by user action |
||
|
r/w |
Whether to expand the child’s tab |
||
|
r/w |
Whether the child’s tab should fill the allocated area |
||
|
r/w |
The string displayed on the child’s tab label |
Style Properties¶
- Inherited:
Name |
Type |
Default |
Flags |
Short Description |
|---|---|---|---|---|
|
|
d/r |
Scroll arrow spacing |
|
|
r |
|
||
|
r |
|
||
|
r |
|
||
|
r |
|
||
|
d/r |
Active tab is drawn with a gap at the bottom |
||
|
|
d/r |
Initial gap before the first tab |
|
|
|
d/r |
Size of tab curvature |
|
|
|
d/r |
Size of tab overlap area |
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
The |
|
the |
|
the |
|
the |
|
Emitted when the user or a function changes the current page. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
container |
r |
Class Details¶
- class Gtk.Notebook(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
The
Gtk.Notebookwidget is aGtk.Containerwhose 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 (seeGtk.Notebook.set_tab_pos()), whether, if there are too many tabs to fit the notebook should be made bigger or scrolling arrows added (seeGtk.Notebook.set_scrollable()), and whether there will be a popup menu allowing the users to switch pages. (seeGtk.Notebook.popup_enable(),Gtk.Notebook.popup_disable())The
Gtk.Notebookimplementation of theGtk.Buildableinterface 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>
- CSS nodes
notebook ├── header.top │ ├── [<action widget>] │ ├── tabs │ │ ├── [arrow] │ │ ├── tab │ │ │ ╰── <tab label> ┊ ┊ ┊ │ │ ├── tab[.reorderable-page] │ │ │ ╰── <tab label> │ │ ╰── [arrow] │ ╰── [<action widget>] │ ╰── stack ├── <child> ┊ ╰── <child>Gtk.Notebookhas a main CSS node with name notebook, a subnode with name header and below that a subnode with name tabs which contains one subnode per tab with name tab.If action widgets are present, their CSS nodes are placed next to the tabs node. If the notebook is scrollable, CSS nodes with name arrow are placed as first and last child of the tabs node.
The main node gets the .frame style class when the notebook has a border (see
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, regarldess of text direction.
- classmethod new()[source]¶
- Returns:
the newly created
Gtk.Notebook- Return type:
Creates a new
Gtk.Notebookwidget with no pages.
- append_page(child, tab_label)[source]¶
- Parameters:
child (
Gtk.Widget) – theGtk.Widgetto use as the contents of the pagetab_label (
Gtk.WidgetorNone) – theGtk.Widgetto be used as the label for the page, orNoneto 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) – theGtk.Widgetto use as the contents of the pagetab_label (
Gtk.WidgetorNone) – theGtk.Widgetto be used as the label for the page, orNoneto use the default label, “page N”menu_label (
Gtk.WidgetorNone) – the widget to use as a label for the page-switch menu, if that is enabled. IfNone, and tab_label is aGtk.LabelorNone, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not aGtk.Label, 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
Gtk.Container.remove(), but additionally informs the notebook that the removal is happening as part of a tab DND operation, which should not be cancelled.New in version 3.16.
- 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
Nonewhen this action widget has not been set- Return type:
Gtk.WidgetorNone
Gets one of the action widgets. See
Gtk.Notebook.set_action_widget().New in version 2.20.
- 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
Noneif the notebook page does not have a menu label other than the default (the tab label).- Return type:
Gtk.WidgetorNone
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
Noneif the widget does not have a menu label other than the default menu label, or the menu label widget is not aGtk.Label. 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.
New in version 2.2.
- 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
Noneif page_num is out of bounds- Return type:
Gtk.WidgetorNone
Returns the child widget contained in page number page_num.
- get_scrollable()[source]¶
-
Returns whether the tab label area has arrows for scrolling. See
Gtk.Notebook.set_scrollable().
- get_show_border()[source]¶
-
Returns whether a bevel will be drawn around the notebook pages. See
Gtk.Notebook.set_show_border().
- get_show_tabs()[source]¶
-
Returns whether the tabs of the notebook are shown. See
Gtk.Notebook.set_show_tabs().
- get_tab_detachable(child)[source]¶
- Parameters:
child (
Gtk.Widget) – a childGtk.Widget- Returns:
Trueif the tab is detachable.- Return type:
Returns whether the tab contents can be detached from self.
New in version 2.10.
- get_tab_hborder()[source]¶
- Returns:
horizontal width of a tab border
- Return type:
Returns the horizontal width of a tab border.
New in version 2.22.
Deprecated since version 3.4: this function returns zero
- get_tab_label(child)[source]¶
- Parameters:
child (
Gtk.Widget) – the page- Returns:
the tab label
- Return type:
Gtk.WidgetorNone
Returns the tab label widget for the page child.
Noneis 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
Noneif the tab label widget is not aGtk.Label. 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 for switching pages in the notebook are drawn.
- get_tab_reorderable(child)[source]¶
- Parameters:
child (
Gtk.Widget) – a childGtk.Widget- Returns:
Trueif the tab is reorderable.- Return type:
Gets whether the tab can be reordered via drag and drop or not.
New in version 2.10.
- get_tab_vborder()[source]¶
- Returns:
vertical width of a tab border
- Return type:
Returns the vertical width of a tab border.
New in version 2.22.
Deprecated since version 3.4: this function returns zero
- insert_page(child, tab_label, position)[source]¶
- Parameters:
child (
Gtk.Widget) – theGtk.Widgetto use as the contents of the pagetab_label (
Gtk.WidgetorNone) – theGtk.Widgetto be used as the label for the page, orNoneto 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) – theGtk.Widgetto use as the contents of the pagetab_label (
Gtk.WidgetorNone) – theGtk.Widgetto be used as the label for the page, orNoneto use the default label, “page N”menu_label (
Gtk.WidgetorNone) – the widget to use as a label for the page-switch menu, if that is enabled. IfNone, and tab_label is aGtk.LabelorNone, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not aGtk.Label, 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) – aGtk.Widget- 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) – theGtk.Widgetto use as the contents of the pagetab_label (
Gtk.WidgetorNone) – theGtk.Widgetto be used as the label for the page, orNoneto 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) – theGtk.Widgetto use as the contents of the pagetab_label (
Gtk.WidgetorNone) – theGtk.Widgetto be used as the label for the page, orNoneto use the default label, “page N”menu_label (
Gtk.WidgetorNone) – the widget to use as a label for the page-switch menu, if that is enabled. IfNone, and tab_label is aGtk.LabelorNone, then the menu label will be a newly created label with the same text as tab_label; if tab_label is not aGtk.Label, 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) – aGtk.Widgetpack_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
Gtk.Boxif you need to pack more than one widget on the same side.Note that action widgets are “internal” children of the notebook and thus not included in the list returned from
Gtk.Container.foreach().New in version 2.20.
- 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.Notebookrefuses 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
Nonegroup name will not be able to exchange tabs with any other notebook.New in version 2.24.
- Parameters:
child (
Gtk.Widget) – the child widgetmenu_label (
Gtk.WidgetorNone) – the menu label, orNonefor 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. See
Gtk.Notebook.set_show_tabs().
- set_tab_detachable(child, detachable)[source]¶
- Parameters:
child (
Gtk.Widget) – a childGtk.Widgetdetachable (
bool) – whether the tab is detachable or not
Sets whether the tab can be detached from self to another notebook or widget.
Note that 2 notebooks must share a common group identificator (see
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.Widgetpointing to the child widget that corresponds to the dropped tab.Note that you should use
Gtk.Notebook.detach_tab() instead ofGtk.Container.remove() 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.static void on_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { GtkWidget *notebook; GtkWidget **child; notebook = gtk_drag_get_source_widget (context); 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.
New in version 2.10.
- set_tab_label(child, tab_label)[source]¶
- Parameters:
child (
Gtk.Widget) – the pagetab_label (
Gtk.WidgetorNone) – the tab label widget to use, orNonefor default tab label
Changes the tab label for child. If
Noneis 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 for switching pages in the notebook are drawn.
- set_tab_reorderable(child, reorderable)[source]¶
- Parameters:
child (
Gtk.Widget) – a childGtk.Widgetreorderable (
bool) – whether the tab is reorderable or not
Sets whether the notebook tab can be reordered via drag and drop or not.
New in version 2.10.
- do_focus_tab(type) virtual¶
- Parameters:
type (
Gtk.NotebookTab) –- Return type:
- do_insert_page(child, tab_label, menu_label, position) virtual¶
- Parameters:
child (
Gtk.Widget) –tab_label (
Gtk.Widget) –menu_label (
Gtk.Widget) –position (
int) –
- Return type:
- do_move_focus_out(direction) virtual¶
- Parameters:
direction (
Gtk.DirectionType) –
- do_page_added(child, page_num) virtual¶
- Parameters:
child (
Gtk.Widget) –page_num (
int) –
- do_page_removed(child, page_num) virtual¶
- Parameters:
child (
Gtk.Widget) –page_num (
int) –
- do_page_reordered(child, page_num) virtual¶
- Parameters:
child (
Gtk.Widget) –page_num (
int) –
- do_reorder_tab(direction, move_to_last) virtual¶
- Parameters:
direction (
Gtk.DirectionType) –move_to_last (
bool) –
- Return type:
- do_switch_page(page, page_num) virtual¶
- Parameters:
page (
Gtk.Widget) –page_num (
int) –
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, x, y)¶
- Signal Name:
create-window- Flags:
- Parameters:
notebook (
Gtk.Notebook) – The object which received the signalpage (
Gtk.Widget) – the tab of notebook that is being detachedx (
int) – the X coordinate where the drop happensy (
int) – the Y coordinate where the drop happens
- Returns:
a
Gtk.Notebookthat page should be added to, orNone.- Return type:
The
::create-windowsignal 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
Gtk.Notebook:group-name).New in version 2.12.
- 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 childGtk.Widgetaffectedpage_num (
int) – the new page number for child
the
::page-addedsignal is emitted in the notebook right after a page is added to the notebook.New in version 2.10.
- 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 childGtk.Widgetaffectedpage_num (
int) – the child page number
the
::page-removedsignal is emitted in the notebook right after a page is removed from the notebook.New in version 2.10.
- 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 childGtk.Widgetaffectedpage_num (
int) – the new page number for child
the
::page-reorderedsignal is emitted in the notebook right after a page has been reordered.New in version 2.10.
- 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 pops up a menu that you can use to go to a page
- Gtk.Notebook.props.group_name¶
- Name:
group-name- Type:
- Default Value:
- Flags:
Group name for tab drag and drop.
New in version 2.24.
- Gtk.Notebook.props.page¶
- Name:
page- Type:
- Default Value:
-1- Flags:
The index of the current page
- Gtk.Notebook.props.scrollable¶
- Name:
scrollable- Type:
- Default Value:
- Flags:
If
True, scroll arrows are added if there are too many tabs 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