Gtk basic learning Summary (1), gtk basic learning Summary
Example of the first GTK program:
# Include <stdio. h>
# Include <gtk/gtk. h>
Int main (int argc, char * argv [])
{
Gtk_init (NULL, NULL); // initialize GTK
GtkWindow * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); // create a window
Gtk_window_set_title (window, "window title"); // you can specify a window title.
G_signal_connect (window, "destroy", gtk_main_quit, 0); // set the "destroy" signal (event) processing function "gtk_main_quit ()" of the window ()"
Gtk_widget_show (window); // display window
Gtk_main (); // program Blocking
Return 0;
}
I. Common Methods
// Widget operation function
Void gtk_widget_show (widget );
Void gtk_widget_hide (widget );
Void gtk_widget_set_sensitive (widget, sensitive );
Void gtk_widget_set_size_request (widget, width, height );
// Window operation function
Gtk_window_set_resizable (window, resizable );
Gtk_window_set_position (window, GTK_WIN_POS_CENTER_ALWAYS );
Gtk_window_maximize (window );
Gtk_container_add (widget iner, widget); // load the widget to the container.
Gtk_AAA_get_BBB ();
Gtk_AAA_set_BBB ();
// Gtk_widget_set_title (widget, "title ");
2. GtkBox Layout
// Create a box
GtkBox * box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0 );
// GtkBox * box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0 );
Gtk_container_add (window, box1 );
Gtk_widget_show (box1 );
// Add button 1
GtkButton * btn1 = gtk_button_new ();
Gtk_button_set_label (btn1, "button 1 ");
Gtk_box_pack_start (box1, btn1, FALSE, FALSE, 0 );
Gtk_widget_show (btn1 );
// Add button 2
GtkButton * btn2 = gtk_button_new ();
Gtk_button_set_label (btn2, "button 2 ");
Gtk_box_pack_start (box1, btn2, FALSE, FALSE, 0 );
Gtk_widget_show (btn2 );
// Add text box 1
GtkEntry * entry1 = gtk_entry_new ();
Gtk_box_pack_start (box1, entry1, FALSE, FALSE, 0 );
Gtk_widget_show (entry1 );
3. grid layout
/*
GtkGrid * grid1 = gtk_grid_new ();
Gtk_container_add (window, grid1 );
Gtk_widget_show (grid1 );
// Gtk_grid_attack (GtkGrid, widget, int left, int top, int width, int height );
// Add button 1
GtkButton * btn1 = gtk_button_new ();
Gtk_button_set_label (btn1, "button 1 ");
Gtk_grid_attach (grid1, btn1, 0, 1, 1 );
Gtk_widget_show (btn1 );
// Add button 2
GtkButton * btn2 = gtk_button_new ();
Gtk_button_set_label (btn2, "button 2 ");
Gtk_grid_attach (grid1, btn2, 1, 0, 1, 1 );
Gtk_widget_show (btn2 );
// Add button 3
GtkButton * btn3 = gtk_button_new ();
Gtk_button_set_label (btn3, "button 3 ");
Gtk_grid_attach (grid1, btn3, 0, 1, 2 );
Gtk_widget_show (btn3 );
*/
Appendix: The above content is a summary of what I learned after learning the teaching video of Teacher Yang zhongke's "C language is also capable of major events (the third edition.