Linux from the beginning to go GTK +-3.0 (4), gtk-3.0
In practical applications, there are often many controls. Similarly, GTK provides many layout schemes, such as Box, Fixed, Table, and Grid.
Next, try Grid layout.
We create example4.c with the following content:
# Include <gtk/gtk. h> static void print_hello (GtkWidget * button, gpointer data); static void activate (GtkApplication * app, gpointer data); int main (int argc, char ** argv) {GtkApplication * app; int app_status; app = gtk_application_new ("org. rain. gtk ", G_APPLICATION_FLAGS_NONE); g_signal_connect (app," activate ", G_CALLBACK (activate), NULL); app_status = g_application_run (G_APPLICATION (app), argc, Argv); g_object_unref (app); return app_status;} static void print_hello (GtkWidget * button, gpointer data) {printf ("Hello, World! \ N ");} static void activate (GtkApplication * app, gpointer data) {GtkWidget * window; GtkWidget * grid; GtkWidget * button; // create a window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "grid test"); // gtk_window_set_default_size (GTK_WINDOW (window), 200,200 ); // create grid = gtk_grid_new (); // Add the grid layout to the window. gtk_container_set_border_width (GTK_CONTAINER (window), 20); gtk_container_add (GTK_CONTAINER (window), grid ); // Add the button to the position (0, 0), and set the height. The width is the unit of button = gtk_button_new_with_label ("Button1"); g_signal_connect (button, "clicked ", g_CALLBACK (print_hello), NULL); gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1); // Add a button to the position (1, 0, and set the height. The width is the unit of button = gtk_button_new_with_label ("Button2"); g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); gtk_grid_attach (GTK_GRID ), button, 1, 0, 1, 1); // Add a button to the position (0, 1), and set the height to a unit, the width is two units: button = Response ("Exit"); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_grid_attach (GTK_GRID), button, 2, 0, 1, 1); // Add a button to the position (), and set the height to one unit. The width is two units. The button = gtk_button_new_with_label ("Exit "); trim (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_grid_attach (GTK_GRID (grid), button, 1, 1, 2, 1); gtk_widget_show_all (window );}
Compile and run:
gcc exampe.c `pkg-config --cflags --libs gtk+-3.0`./a.out
Running result:
Gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1 );
The following four parameters of the function are represented in sequence: row number, column number, horizontal span, and vertical span.