sample gtk+ program first gtk+ program

Example we will show a basic window

#include

int main( int argc, char *argv[])
{
GtkWidget *window;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);

gtk_main();

return 0;
}

The above code is to show basic window on screen

gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`

by the above we compile the program

Line by line code analysis

gtk_init(&argc, &argv);

Here we initiate the GTK+ library.

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

We create a GtkWindow widget. The window type is GTK_WINDOW_TOPLEVEL. Toplevel windows have a titlebar and a border. They are managed by the window manager.

gtk_widget_show(window);

After we have created a widget, we must show it.

gtk_main();

This code enters the GTK+ main loop. From this point, the application sits and waits for events to happen.



its shows as above

No comments:

 
Top Blogs