Introduction
In this example, we create a simple text label. The GtkLabel is a not-editable text field that is usually used to provide names or descriptions for other widgets. In future programs, we will use labels next to other widgets like single line text areas and drop down lists. There’s not too much else to say about labels…they are just about the least complicated widget there is.
Source Code
/*
*File name: label.c
*/#include
#include/*– This function allows the program to exit properly when the window is closed –*/
gint destroyapp (GtkWidget *widget, gpointer gdata)
{
g_print (“Quitting…\n”);
gtk_main_quit();
return (FALSE);
}int main (int argc, char *argv[])
{
/*– Declare the GTK Widgets used in the program –*/
GtkWidget *window;
GtkWidget *label;/*– Initialize GTK –*/
gtk_init (&argc, &argv);/*– Create the new window –*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);/*– Create a label –*/
label = gtk_label_new(“GtkLabel”);/*– Connect the window to the destroyapp function –*/
gtk_signal_connect(GTK_OBJECT(window), “delete_event”, GTK_SIGNAL_FUNC(destroyapp), NULL);/*– Add the button to the window –*/
gtk_container_add(GTK_CONTAINER (window), label);/*– Add a border to the window to give the button a little room –*/
gtk_container_border_width (GTK_CONTAINER (window), 15);/*– Display the widgets –*/
gtk_widget_show(label);
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 label.c -o label `gtk-config –cflags` `gtk-config –libs`
Execute the Program
./label






