5 * The data passed to this function is printed to stdout */
6 void callback( GtkWidget
*widget
,
9 g_print ("Hello again - %s was pressed\n", (char *) data
);
12 /* This callback quits the program */
13 gint
delete_event( GtkWidget
*widget
,
29 gtk_init (&argc
, &argv
);
32 /* Create a new window */
33 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
35 /* Set the window title */
36 gtk_window_set_title (GTK_WINDOW (window
), "Table");
38 /* Set a handler for delete_event that immediately
40 g_signal_connect (G_OBJECT (window
), "delete_event",
41 G_CALLBACK (delete_event
), NULL
);
43 /* Sets the border width of the window. */
44 gtk_container_set_border_width (GTK_CONTAINER (window
), 20);
46 /* Create a 2x2 table */
47 table
= gtk_table_new (2, 2, TRUE
);
49 /* Put the table in the main window */
50 gtk_container_add (GTK_CONTAINER (window
), table
);
52 /* Create first button */
53 button
= gtk_button_new_with_label ("button 1");
55 /* When the button is clicked, we call the "callback" function
56 * with a pointer to "button 1" as its argument */
57 g_signal_connect (G_OBJECT (button
), "clicked",
58 G_CALLBACK (callback
), (gpointer
) "button 1");
61 /* Insert button 1 into the upper left quadrant of the table */
62 gtk_table_attach_defaults (GTK_TABLE (table
), button
, 0, 1, 0, 1);
64 gtk_widget_show (button
);
66 /* Create second button */
68 button
= gtk_button_new_with_label ("button 2");
70 /* When the button is clicked, we call the "callback" function
71 * with a pointer to "button 2" as its argument */
72 g_signal_connect (G_OBJECT (button
), "clicked",
73 G_CALLBACK (callback
), (gpointer
) "button 2");
74 /* Insert button 2 into the upper right quadrant of the table */
75 gtk_table_attach_defaults (GTK_TABLE (table
), button
, 1, 2, 0, 1);
77 gtk_widget_show (button
);
79 /* Create "Quit" button */
80 button
= gtk_button_new_with_label ("Quit");
82 /* When the button is clicked, we call the "delete_event" function
83 * and the program exits */
84 g_signal_connect (G_OBJECT (button
), "clicked",
85 G_CALLBACK (delete_event
), NULL
);
87 /* Insert the quit button into the both
88 * lower quadrants of the table */
89 gtk_table_attach_defaults (GTK_TABLE (table
), button
, 0, 2, 1, 2);
91 gtk_widget_show (button
);
93 gtk_widget_show (table
);
94 gtk_widget_show (window
);