GtkLabel-sample gtklabel code gtk widgets

The GtkLabel widget displays text.

#include gtk/gtk.h
int main( int argc, char *argv[])
GtkWidget *window;
GtkWidget *label;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "Nymphetamine");
gtk_window_set_default_size(GTK_WINDOW(window), 350, 400);
label = gtk_label_new("Cold was my soul\n\
Untold was the pain\n\
I faced when you left me\n\
A rose in the rain....\n\
So I swore to the razor\n\
That never, enchained\n\
Would your dark nails of faith\n\
Be pushed through my veins again\n\
Bared on your tomb\n\
I'm a prayer for your loneliness\n\
And would you ever soon\n\
Come above onto me?\n\
For once upon a time\n\
On the binds of your lowliness\n\
I could always find the slot for your sacred key ");
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gtk_container_add(GTK_CONTAINER(window), label);
g_signal_connect_swapped(window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
return 0;

The example shows lyrics of a song.

label = gtk_label_new("Cold was my soul\n\
Untold was the pain\n\

We create a GtkLabel widget. We can create multiline text label by using a new line character. Note the escape character. We use a rather long string and we don't want to put all the text into one line. In such cases, we can use an escape character.

gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);

We center our label.

Figure: GtkLabel

No comments: