Gtk - GTK+ Hello World

GTK+ Hello World

The following code presents a graphical GTK+ hello-world program in the C programming language. This program has a window with the title "Hello, world!" and a label with similar text.

#include int main (int argc, char *argv) { GtkWidget *window; GtkWidget *label; gtk_init(&argc, &argv); /* Create the main, top level window */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* Give it the title */ gtk_window_set_title(GTK_WINDOW(window), "Hello, world!"); /* ** Map the destroy signal of the window to gtk_main_quit; ** When the window is about to be destroyed, we get a notification and ** stop the main GTK+ loop by returning 0 */ g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); /* ** Assign the variable "label" to a new GTK label, ** with the text "Hello, world!" */ label = gtk_label_new("Hello, world!"); /* Plot the label onto the main window */ gtk_container_add(GTK_CONTAINER(window), label); /* Make sure that everything, window and label, are visible */ gtk_widget_show_all(window); /* ** Start the main loop, and do nothing (block) until ** the application is closed */ gtk_main; return 0; }

Using GCC and pkg-config in a Unix shell, this code can be compiled with the following command (assume above source has file name "helloworld.c"):

$ gcc -Wall helloworld.c -o helloworld $(pkg-config --cflags --libs gtk+-3.0)

Read more about this topic:  Gtk

Famous quotes containing the word world:

    You can’t, in sound morals, condemn a man for taking care of his own integrity. It is his clear duty. And least of all can you condemn an artist pursuing, however humbly and imperfectly, a creative aim. In that interior world where his thought and his emotions go seeking for the experience of imagined adventures, there are no policemen, no law, no pressure of circumstance or dread of opinion to keep him within bounds. Who then is going to say Nay to his temptations if not his conscience?
    Joseph Conrad (1857–1924)