1#include <gtk/gtk.h>
2#include <glib/gstdio.h>
3
4static void
5print_hello (GtkWidget *widget,
6 gpointer data)
7{
8 g_print (format: "Hello World\n");
9}
10
11static void
12quit_cb (GtkWidget *widget, gpointer data)
13{
14 GtkWindow *window = data;
15
16 gtk_window_close (window);
17}
18
19static void
20activate (GtkApplication *app,
21 gpointer user_data)
22{
23 /* Construct a GtkBuilder instance and load our UI description */
24 GtkBuilder *builder = gtk_builder_new ();
25 gtk_builder_add_from_file (builder, filename: "builder.ui", NULL);
26
27 /* Connect signal handlers to the constructed widgets. */
28 GObject *window = gtk_builder_get_object (builder, name: "window");
29 gtk_window_set_application (GTK_WINDOW (window), application: app);
30
31 GObject *button = gtk_builder_get_object (builder, name: "button1");
32 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
33
34 button = gtk_builder_get_object (builder, name: "button2");
35 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
36
37 button = gtk_builder_get_object (builder, name: "quit");
38 g_signal_connect_swapped (button, "clicked", G_CALLBACK (quit_cb), window);
39
40 gtk_widget_show (GTK_WIDGET (window));
41 g_object_unref (object: builder);
42}
43
44int
45main (int argc,
46 char *argv[])
47{
48#ifdef GTK_SRCDIR
49 g_chdir (GTK_SRCDIR);
50#endif
51
52 GtkApplication *app = gtk_application_new (application_id: "org.gtk.example", flags: G_APPLICATION_FLAGS_NONE);
53 g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
54
55 int status = g_application_run (G_APPLICATION (app), argc, argv);
56 g_object_unref (object: app);
57
58 return status;
59}
60

source code of gtk/examples/builder.c