|
GTK+ examples : A Basic Window
|
by Brent Fox
Last Modified: Wednesday, 19-May-2004 11:54:45 EDT
|
Introduction
|
   
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.
|
|
Screenshot
|
Remember that you will have to press ctrl-c in the terminal from which you executed the program in order to kill it.
|
|
Source Code
|
Source code for this example is also available in the file window.c
/*
*File name: window.c
*/
#include <gtk/gtk.h>
#include <glib.h>
int main (int argc, char *argv[])
{
/*-- Declare the GTK Widgets used in the program --*/
GtkWidget *window;
/*-- Initialize GTK --*/
gtk_init (&argc, &argv);
/*-- Create the new window --*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*-- Display the window --*/
gtk_widget_show(window);
/*-- Start the GTK event loop --*/
gtk_main();
/*-- Return 0 if exit is successful --*/
return 0;
}
|
|
Compile the Source Code
|
gcc -Wall -g window.c -o window `gtk-config --cflags` `gtk-config --libs`
|
|
Execute the Program
|
./window
|
|
What's Related
|
|
|
|
|
|
|
All Rights Reserved Linux Headquarters © 2000-2007
Linux is a registered trademark of Linus Torvalds
All logos are registered trademarks of their respective owners
Last modified: Wednesday, May 19, 2004
|
|
|