Friday, December 6, 2013

Install gtk+ 2.0 on Raspberry Pi and "Hello World" to GTK+

This post show how to install gtk+2.0 on Raspberry Pi, and create our first "Hello World" of GTK+ on Raspberry Pi.

GTK+ program on Raspberry Pi
GTK+ program on Raspberry Pi
To install gtk+ 2.0, enter the command:
$ sudo apt-get install libgtk2.0-dev

After installed, create our first GTK+ program, name it hellogtk.c
#include <gtk/gtk.h>

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);
}

Enter the command to compile hellogtk.c:
gcc hellogtk.c -o hellogtk `pkg-config --cflags --libs gtk+-2.0`

Run the generated program:
$ ./hellogtk

hellogtk
./hellogtk



Next:
- Modified "Hello GTK+" to terminal application when the GtkWindow is destroyed, and add a button to print something.

Related:
Install GTK+ 3.0 on Raspberry Pi

No comments: