hello-world.c 1.18 KB
Newer Older
1 2 3 4 5 6 7 8 9
#include <gtk/gtk.h>

static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

10 11 12
static void
activate (GtkApplication *app,
          gpointer        user_data)
13 14 15
{
  GtkWidget *window;
  GtkWidget *button;
16
  GtkWidget *button_box;
17

18 19 20
  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
21

22 23
  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);
24 25 26 27

  button = gtk_button_new_with_label ("Hello World");
  g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
28
  gtk_container_add (GTK_CONTAINER (button_box), button);
29

30 31
  gtk_widget_show_all (window);
}
32

33 34 35 36 37 38
int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;
39

40 41 42 43
  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);
44

45
  return status;
46
}