The notebook control for GTK common Controls (Gtknotebook)

Source: Internet
Author: User
Tags gtk

notebook controls, which allow users to switch multiple interfaces in a tabbed manner. Using a notebook control is a wise choice when we need to switch to multiple windows.



Creation of notebook controls:

Gtkwidget *gtk_notebook_new (void);

Return value: Notebook control pointer


To set the location of page labels:

void Gtk_notebook_set_tab_pos (Gtknotebook *notebook,

Gtkpositiontype POS);

Notebook: Notebook controls

The POS values are as follows:

Gtk_pos_left: Left
Gtk_pos_right: Right
Gtk_pos_top: Up
Gtk_pos_bottom: Next


Append page:
Gint Gtk_notebook_append_page (

< Span style= "Color:rgb (255,0,0)" >

gtknotebook *notebook, 

< Span style= "Color:rgb (255,0,0)" >

gtkwidget *child,  p>

Gtkwidget *tab_label);

Notebook: A notebook that accommodates other controls
Child: sub-controls placed on a notebook page
Tab_label: To add the title name of the page
return Value: Success return value page face (starting from 0), failed return-1
Add a page at the specified location (starting from 0):
Gint Gtk_notebook_insert_page (

Gtknotebook *notebook,

Gtkwidget *child,

Gtkwidget *tab_label,

Gint position);

Notebook: A notebook that accommodates other controls
Child Child controls placed on a notebook page
Tab_label: To add the title name of the page
Position: The position of the page, starting from 0, if-1 represents the last
Return value: Success return value page face (starting from 0), failed return-1
set the Start page, starting from 0, which is equivalent to setting the page display: void Gtk_notebook_set_current_page (

Gtknotebook *notebook,

Gint page_num);

Notebook: The notebook control to be set
page_num: Number of pages

Common signal:"Switch-page" "Switch-page" signal is triggered when the page is toggled

The example code is as follows:
 #include <gtk/gtk.h>//"switch-page" signal processing function, page_num refers to the first few pages, starting from 0 void Deal_switch_pape (Gtknotebook *notebook, Gpointer page,guint page_num, Gpointer user_data) {printf ("I'm%d pages \ n", page_num+1);} int main (int argc, char *argv[]) { Gtk_init (&AMP;ARGC, &AMP;ARGV); Initialize Gtkwidget *window = gtk_window_new (gtk_window_toplevel); Create the main window gtk_widget_set_size_request (window, 400, 300);//Set window size Gtkwidget *notebook = Gtk_notebook_new (); Create a Notebook control Gtk_container_add (Gtk_container (window), notebook); The position of the notebook in the window//page label can be in four positions: up, down, left, or right.  Gtk_notebook_set_tab_pos (Gtk_notebook (notebook), gtk_pos_top); Top//First page Gtkwidget *label = gtk_label_new ("Page One");//Create label Gtkwidget *box = Gtk_hbox_new (TRUE, 5);//Create Layout Gtkwidget *b Utton_one = Gtk_button_new_with_label ("I am the first page"); Gtkwidget *button_two = Gtk_button_new_with_label ("I am the button of the first page"); Gtk_container_add (Gtk_container (box), Button_one); Gtk_container_add (Gtk_container (box), button_two);/* Gtk_notebook_append_page (Gtknotebook *notebook, GtkWidget *cHild, * gtkwidget *tab_label); * Insert page to the back end (append) or front end (prepend) of the notebook to add the page. * Child is a sub-control placed on a notebook page, it must be created separately, typically a container * Tab_label is the label of the page to be added. */gtk_notebook_append_page (Gtk_notebook (notebook), box, label); The second page is label = gtk_label_new ("page two");//create Label box = Gtk_hbox_new (TRUE, 5);//Create layout Button_one = Gtk_button_new_with_ Label ("I Am the second page"), Button_two = Gtk_button_new_with_label ("I am the button for the second page"), Gtk_container_add (gtk_container box), Button_one) Gtk_container_add (Gtk_container (box), Button_two) Gtk_notebook_append_page (Gtk_notebook (notebook), box, label); The third page, add a page at the specified location, starting with 0 Button_one = Gtk_button_new_with_label ("I am the third page implemented through Insert_page"); label = Gtk_label_new (" Page Three "); Gtk_notebook_insert_page (Gtk_notebook (notebook), Button_one, label, 2); Processing the signal, when switching the page, will trigger "switch-page" signal g_signal_connect (Notebook, "Switch-page", G_callback (Deal_switch_pape), NULL); GTK _widget_show_all (window); Show all controls//Settings Start Page (2nd page), calculated from 0, equivalent to set 2nd page display Gtk_notebook_set_current_page (Gtk_notebook (notebook), 1); Gtk_main (); Main Event loop return 0;  }



The program runs as follows:


Please click here for source code download.

The notebook control for GTK common Controls (Gtknotebook)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.