View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > GTK2

From LQWiki

Jump to: navigation, search

GTK2 is an API toolkit for creating portable GUIs that run on multiple platforms. The acronym GTK derives from "GIMP Toolkit." In it's original form, the GTK draws GIMP graphics to interface with X Window System using GDK objects and a library called GLib. This used to be called Motif but was renamed to GTK in 1996. When the objects took on a decided object-orientation the toolkit was renamed to GTK+. And as it has evolved with the GNOME project it added many functions and became second generation, GTK2.

There are several language API bindings that work with GTK2 including C++, Java, Perl, Python, C#, and Visual Basic. By working in the bound language, a user can create useful GUIs to whatever functions that can be programmed and compile/run them on various platforms.

The recommended way to use it is to write a set of callbacks using a set of portable library types in the language binding of your choice. The callbacks provide functions for features like buttons and fields that you add to graphical windows. An executive program starts the whole application off by generating the graphical objects and waiting for commands from the callbacks. These callbacks are nothing but functions compiled and linked with the executive that perform the programmer's bidding in response to "events" such as button presses.

The GTK2 types are platform independent. The user can compile and run the finished GTK2 project on any platform that GTK2 can be installed. "gdouble" would replace "double," for instance, and would be compiled properly behind the scenes to work with Windows, Linux, etc.

There are two books written about GTK+:

Krause, Andrew Foundations of GTK+ Development. Berkeley, CA, Apress, Inc. 2007

Warkus, Matthias. The Official GNOME 2 Developer's Guide. San Francisco, CA, No Starch Press, Inc. 2004.

The Wikipedia site GTK2 has even more information.

No mention of GTK2 would be complete without an explanation of its modern companion, Glade2. Glade2 is a "what you see is what you get" (WYSIWYG) GUI interface to GTK2 itself. Its capabilities are limited, however, in particular once a complete application has been generated by Glade2 it is very difficult to iterate to add features. Therefore, it is best to use it for generating complicated graphical object pieces that are instantiated by a main executive program that has been generated manually.

The user who wishes to plunge into a GTK2 project will find it to be straightforward. There are many examples to draw upon. There are many language bindings to choose from so learning a new language is unnecessary. The primary learning will be thinking dynamically about an executive that is running all the time waiting for events from the callbacks. Once a rudimentary application has been formed, an experienced programmer will find it is easy to grow incrementally into a large application.


Personal tools