Our first GTK+ program will be nothing more than a basic window. There are no event handlers, which means that the window will not respond to any user input such as mouse clicks. Although clicking the X button on the title bar to exit the program will cause the window to disappear, the process is still active. You will have to press ctrl-c from the command line from which you executed the program in order to kill it.
When you compile the source code, please note that the quotes used in the command gcc -Wall -g window.c -o window `gtk-config –cflags` `gtk-config –libs` are single backquotes (the one on the ~ key). I don’t know why this is, but it won’t work any other way.
As you can see, it doesn’t take very much code to get something basic on the screen.
Remember that you will have to press ctrl-c in the terminal from which you executed the program in order to kill it.
*File name: window.c
int main (int argc, char *argv)
/*– Declare the GTK Widgets used in the program –*/
/*– Initialize GTK –*/
gtk_init (&argc, &argv);
/*– Create the new window –*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*– Display the window –*/
/*– Start the GTK event loop –*/
/*– Return 0 if exit is successful –*/
Compile the Source Code
gcc -Wall -g window.c -o window `gtk-config –cflags` `gtk-config –libs`
Execute the Program