GTK+ is a graphical user interface (GUI) tool kit. That is, it's a library (or, in fact, a collection of several closely related libraries) that allow you to create GUI-based applications. Think of GTK+ as a toolbox in which you can find many ready building blocks for creating GUIs.
Originally, GTK+ was created as a spin-off of another well-known open source project: the GNU Image Manipulation Program (GIMP). While working on early GIMP versions, Peter Mattis and Spencer Kimball created GTK (which stands for GIMP Toolkit) as an alternative to the Motif tool kit, which at that time was not free. (The plus sign was added to the name later, when the tool kit gained object-oriented features and extensibility.)
That was almost 10 years ago. Today, a lot of activity is still going on with the latest GTK+ version -- 2.8 -- and while GIMP certainly continues to be one of the best-known programs using GTK+, it is by far not the only one. Literally thousands of applications have been written for GTK+, and at least two major desktop environments (Xfce and GNOME) use GTK+ to provide a full working environment for users.
Using a library like GTK+ has several advantages over writing your own GUI code. For example, it can provide significant development time savings, freeing you to focus on what's really important and unique to your project, instead of duplicating common functionality. For your users, it means greater consistency among the applications they use: Wherever the tool kit works, their applications will follow. Just as with LEGOs, the fact that everyone uses one compatible size means your designs can be shared with anyone who uses the library, no matter where they use it.
In actuality, modern GUI tool kits do more than merely avoid duplication. They offer many advanced capabilities that users have come to expect in their applications and which wouldn't be attainable otherwise because the time and work investment in such tool kits exceeds whatever you could spend on a single application. Therefore, if using a GUI in your application is important to you, use a tool kit. There's simply no other way. Now, the only question left is, which tool kit should you use?
Whatever your development needs, GTK+ might be just the answer you're looking for. GTK+ has a lot to offer:
- It's both modern and actively developed and maintained, with a vibrant surrounding community.
- It offers a wide array of options for extending your work to as many people as possible, including a sophisticated framework for internationalization, localization, and accessibility.
- It's simple and easy to use, both for developers and users.
- It's well designed, flexible, and extensible.
- It's free software with a liberal open source license.
- It's portable, both from the user's and the developer's perspective.
GTK+ is written using techniques considered state of the art in software development, and whenever flaws are discovered (and they are because no software is perfect), the developers do their best to fix them in the next version. Using modern software means you won't be stuck with an abandoned piece of work, left to rot on the sidetrack of history.
Ongoing maintenance and development also means that you have the ability to influence the direction the tool kit will take in the future. In addition, as new releases occur, new features, and functionality based on user feedback is introduced and old problems are remedied.
When you're creating software for all to use, keep three keywords in mind: internationalization, localization, and accessibility (commonly abbreviated i18n, l10n, and a11y, respectively).
Internationalization is the process of preparing your program for use by speakers of languages other than the one in which the application was developed, thereby making the application independent of any assumptions about any particular language.
i18n is much more than simply translating the text your program uses. It means consideration for different scripts and alphabets used, different writing directions, special processing required to display many languages, and providing appropriate methods for users to input text. Not every language can simply map each letter to a different key on the keyboard, and you have to account for even greater complexities, such as making sure that correct plurals are used in error messages.
Localization is closely related to i18n because preparing your application for an international audience is much more than just changing languages. Your program must be able to understand and respect different conventions used for dates, currency display, numeric notations, text sorting, and many nuances you might not be even aware of -- such as the use of symbols that may be considered inappropriate or offensive in different parts of the world.
Just like i18n, proper l10n requires extensive provisions in code that you can't easily add as an afterthought. GTK+ equips you with the right tools for i18n and l10n, resulting in code (and binaries) that can be run with many languages and locales unmodified. All you need to switch the locale is a set of data distributed with the operating system (for l10n) or with a translation file that can be worked on and distributed independently of an actual program (for i18n). The resulting flexibility is something that your developers, your translators, and your users will love.
Accessibility is what makes it possible for everyone to use your program. Some users may have poor vision, some might not be able to use a keyboard or mouse, and some might only be able to move their eyes. Making sure that every user who wants to can use your application takes a lot of work. Fortunately, GTK+ provides a way for you to get instant support through a sophisticated pre-existing a11y framework that requires little to no work on your part. Thanks to this framework (which, is a de-facto standard on UNIX® systems), you can bring your application to all kinds of users.
You, too, can enjoy the many benefits of a11y -- like the ability to perform automated GUI tests. By making your application readable to the accessibility software special-needs users run, you have also made it accessible to testing software that can, for instance, check for proper behavior -- something that poses great problems in traditional GUI programming. (It's also worth remembering that a11y is no longer considered a "nice" thing to have these days. Many regulations -- for example, the rules for U.S. governmental-use software -- actually require software to have proper support for special-needs users.)
The above three points are probably reason enough to use a tool kit -- particularly GTK+, which has excellent support in all these areas. This support is by no means perfect, but it is among the best of what you can get with contemporary software, and the importance of incorporating these keywords into your application cannot be stressed enough. In today's world, where computers are ubiquitous and users working with them are numerous and unique, it simply isn't possible to accept as a full product an application that leaves out whole groups of users.
This one should be obvious, but it really means a lot. A tool kit should be easy for and on its users, making it possible to create interfaces that are simple, intuitive, and pleasant to use, even for a novice. Creating a correct model of human-computer interaction isn't a trivial task, and GTK+ is the result of many hours of work, as well as the product of numerous, sometimes difficult decisions.
GTK+ is also easy to use for you as a developer. It lets you say what you want to say in a straightforward way, without overburdening you with the formal cruft that computers tend to impose on humans to compensate for their inherent lack of imagination.
GTK+ is written in a way that allows its maintainers to add new functionality and its users both to employ that functionality without straining the basic design, and to use it in a way that best fits their needs. The tool kit is also extensible, meaning that you can add your own blocks to it and use them the same way you would use built-in blocks. For instance, you can write your own control element to, say, display scientific data that your application works with and have it properly follow the user's choice of visual style, just like native GTK+ controls do.
Further, GTK+ is customizable, making it possible for you to adapt it to your needs. GTK+ has a system for propagating settings among all applications, including the choice of a theme. A theme is a set of customizations distributed together that affect how the basic controls that GTK+ uses look and, to a certain extent, behave. Using themes, you can (for example) mimic the look and feel of another operating system (see Figure 1).
Figure 1. Sample looks for GTK+ applications
Free software means that everyone is free not only to obtain and use the tool kit but also to modify and redistribute it, provided that certain conditions are met. Liberal open source license means that these conditions are not terribly restrictive, and the degree of freedom you get is significant. Most importantly, GTK+ has adopted the Lesser General Public License (LGPL) license, which is a less-restrictive license in the family of GNU licenses. LGPL allows you to freely get, modify, and distribute any software it covers, as long as you make your modifications free, as well. LGPL also allows anyone to use functions provided by the library without requiring the user to open the application code. (This is important for many industrial uses, where it's undesirable or downright impossible to make the code public, often because of previous agreements and licenses.) With the LGPL license, you can be both a good partner and a good open source citizen.
Last but not least, GTK+ is portable, which means that users can run it on many platforms and systems. In contrast, developers can provide their software to numerous users, writing the program only once, and can also use many different programming and development platforms, tools, and programming languages. All this translates to a greater potential audience and your being able to leverage a wider array of skills and tools better suited to your needs.
All these strengths combined make GTK+ a solid base for software development. With it, you'll be able to concentrate on solving actual problems, instead of reinventing the wheel, and you can be confident that the application you create will behave the way users expect it to, solving their problems, instead of creating new ones.
This article provided a quick and high-level overview of GTK+ without going into much detail. In the next installment, you'll see actual GTK+ code in action. I'll show you how the code behaves in reality, introduce some of the tools available, and demonstrate how GTK+ tackles different platforms and languages. In the final article, you'll see examples of GTK+ in the wild, and I'll analyze the problems of compatibility and portability, deployment, and fitting GTK+ to your specific needs. Last but not least, you'll find enough pointers that you'll know where to look for assistance when you decide to use GTK+ in your own projects.
Visit GTK+ for more information about the tool kit.
The GTK+ API reference page is essential for any developer.
The Official GNOME 2 Developer's Guide by Matthias Warkus (No Starch Press, 2004) covers GNOME 2, including programming with GTK+.
Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.
Get products and technologies
Get the official GTK+ source code tarballs.
Get the first and still one of the most popular GTK+ applications: GIMP.
Check out GNOME, the usability-focused desktop built using GTK+.
Try Xfce, a fast and easy desktop, also developed with GTK+.
Visit Gnomefiles and get more than 1,000 applications built using GTK+.
Innovate your next open source development project with IBM trial software, available for download or on DVD.
Get support and ask questions about developing software with GTK+ at the GTK+ mailing lists.
Get involved in the developerWorks community by participating in developerWorks blogs.