4 print_hello (GtkWidget *widget,
7 g_print ("Hello World\n");
18 /* This is called in all GTK applications. Arguments are parsed
19 * from the command line and are returned to the application.
21 gtk_init (&argc, &argv);
23 /* create a new window, and set its title */
24 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
25 gtk_window_set_title (GTK_WINDOW (window), "Grid");
26 g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
27 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
29 /* Here we construct the container that is going pack our buttons */
30 grid = gtk_grid_new ();
32 /* Pack the container in the window */
33 gtk_container_add (GTK_CONTAINER (window), grid);
35 button = gtk_button_new_with_label ("Button 1");
36 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
38 /* Place the first button in the grid cell (0, 0), and make it fill
39 * just 1 cell horizontally and vertically (ie no spanning)
41 gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
43 button = gtk_button_new_with_label ("Button 2");
44 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
46 /* Place the second button in the grid cell (1, 0), and make it fill
47 * just 1 cell horizontally and vertically (ie no spanning)
49 gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1);
51 button = gtk_button_new_with_label ("Quit");
52 g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
54 /* Place the Quit button in the grid cell (0, 1), and make it
57 gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 2, 1);
59 /* Now that we are done packing our widgets, we show them all
60 * in one go, by calling gtk_widget_show_all() on the window.
61 * This call recursively calls gtk_widget_show() on all widgets
62 * that are contained in the window, directly or indirectly.
64 gtk_widget_show_all (window);
66 /* All GTK applications must have a gtk_main(). Control ends here
67 * and waits for an event to occur (like a key press or a mouse event),
68 * until gtk_main_quit() is called.