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 (
gtknotebook *notebook,
gtkwidget *child,
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: sub-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 (
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>void deal_switch_page (gtknotebook *notebook, Gpointer page, Guint page_num, gpointer data) { printf ("I am page%d \ n", page_num+1); return;} int main (int argc, char *argv[]) {//1.GTK environment gtk_init (&ARGC, &ARGV); 2. Create a window Gtkwidget *window = gtk_window_new (gtk_window_toplevel); Set Window Size gtk_widget_set_size_request (Windows, 400, 300); 3. Create a notebook control gtkwidget *notebook = Gtk_notebook_new (); Gtk_container_add (Gtk_container (window), notebook); 4. Page label location, there can be four kinds of positions: upper, lower, left or right Gtk_notebook_set_tab_pos (Gtk_notebook (notebook), gtk_pos_top);//Top//5. Create a horizontal layout Gtkwidget *hbox = Gtk_hbox_new (TRUE, 5); Gtk_container_add (Gtk_container (window), hbox); 6. First page Gtkwidget *label = gtk_label_new ("Page One"); Gtkwidget *button1 = Gtk_button_new_with_label ("I am the first page"); Gtk_container_add (Gtk_container (Hbox), button1); GtkwidGet *button2 = Gtk_button_new_with_label ("I am the button for the first page"); Gtk_container_add (Gtk_container (Hbox), button2); Gtk_notebook_append_page (Gtk_notebook (notebook), Hbox, label); 7. Second page label = gtk_label_new ("page two"); Hbox = Gtk_hbox_new (TRUE, 5); Button1 = Gtk_button_new_with_label ("I am the second page"); Gtk_container_add (Gtk_container (Hbox), button1); Button2 = Gtk_button_new_with_label ("I am a button on the second page"); Gtk_container_add (Gtk_container (Hbox), button2); Gtk_notebook_append_page (Gtk_notebook (notebook), Hbox, label); 8. The third page, add a page at the specified location, starting with 0 label = gtk_label_new ("Page Three"); Button1 = Gtk_button_new_with_label ("I am the third page implemented through Insert_page"); Gtk_notebook_insert_page (Gtk_notebook (notebook), Button1, label, 2); 9. Processing the signal, when switching the page, will trigger "switch-page" signal g_signal_connect (Notebook, "Switch-page", G_callback (Deal_switch_page), NULL) ; 10. Set the default Start page to the second page, starting from 0, that is 1 Gtk_notebook_set_currEnt_page (Gtk_notebook (NOTEBOOK), 1); 11. Display all Pages gtk_widget_show_all (window); 12. Main Event loop Gtk_main (); return 0;}
Operation Result:
source Download: http://download.csdn.net/download/lianghe_work/8945145
Turn from:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The notebook control for GTK common Controls (Gtknotebook)