Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
GTK+

GTK+

Discussion
Ask a question about 'GTK+'
Start a new discussion about 'GTK+'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
GTK+ is a cross-platform
Cross-platform
In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms...

 widget toolkit
Widget toolkit
In computing, a widget toolkit, widget library, or GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces...

 for creating graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

s. It is licensed under the terms of the GNU LGPL
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

, allowing both free
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 and proprietary
Proprietary software
Proprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...

 software to use it. It is one of the most popular toolkits for the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

, along with Qt
Qt (toolkit)
Qt is a cross-platform application framework that is widely used for developing application software with a graphical user interface , and also used for developing non-GUI programs such as command-line tools and consoles for servers...

.

The name GTK+ originates from GTK; the plus was added to distinguish an enhanced version. It was originally created for the GNU Image Manipulation Program (GIMP), a free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 raster graphics editor
Raster graphics editor
A raster graphics editor is a computer program that allows users to paint and edit pictures interactively on the computer screen and save them in one of many popular “bitmap” or “raster” formats such as JPEG, PNG, GIF and TIFF....

, in 1997 by Spencer Kimball
Spencer Kimball
Spencer Kimball is a computer programmer most notable for his early work on the GNU Image Manipulation Program .In 1995, while students at the University of California at Berkeley, Kimball and his classmate Peter Mattis developed the first version of The GIMP as a class project...

 and Peter Mattis
Peter Mattis
Peter Mattis is a computer programmer most notable for his early work on the GNU Image Manipulation Program .In 1995, while students at the University of California at Berkeley, Mattis and his classmate Spencer Kimball developed the first version of The GIMP as a class project...

, members of eXperimental Computing Facility
EXperimental Computing Facility
Founded in 1986, the eXperimental Computing Facility is an undergraduate computing-interest organization...

 (XCF) at the University of California, Berkeley
University of California, Berkeley
The University of California, Berkeley , is a teaching and research university established in 1868 and located in Berkeley, California, USA...

. It is now maintained by members of the GNOME Foundation
GNOME Foundation
The GNOME Foundation is a non-profit organization based in Cambridge, Massachusetts, United States, coordinating the efforts in the GNOME project.-Purpose:...

.

Design


GTK+ is an object-oriented widget toolkit
Widget toolkit
In computing, a widget toolkit, widget library, or GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces...

 written in the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

; object-orientation is achieved by using the GLib object system
GObject
The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability...

. On the X11 display server, GTK+ uses Xlib
Xlib
Xlib is an X Window System protocol client library written in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the protocol...

 to draw widgets. Using Xlib provides flexibility and allows GTK+ to be used on platforms where the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

 is unavailable. While GTK+ is primarily targeted at the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

, other platforms are supported, including Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 (interfaced with the Windows API
Windows API
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name "Windows API" more accurately reflects its roots in 16-bit Windows and its support on...

), and Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 (interfaced with Quartz
Quartz (graphics layer)
Quartz specifically refers to a pair of Mac OS X technologies, each part of the Core Graphics framework: Quartz 2D and Quartz Compositor. It includes both a 2D renderer in Core Graphics and the composition engine that sends instructions to the graphics card...

). HTML5 and Wayland
Wayland (display server)
Wayland is a display server protocol for the Unix-like operating systems and a library for Linux implementing that protocol.Wayland provides a method for compositing window managers to communicate directly with applications and to communicate directly with video and input hardware...

 backends are in development.

GTK+ can be configured to change the look of the widgets drawn; this is done using different display engines. Several display engines exist which try to emulate the look of the native widgets on the platform in use.

Programming language bindings


A library written in one programming language may be used in another programming language if bindings
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...

 are written; GTK+ has bindings in many languages.

See the table below:
! Language
! Name
! Supported?> ! Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...


| GtkAda
| style="text-align:center;" | Partial support up to 2.18> ! C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....


| GTK+
| > ! C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...


| gtkmm
Gtkmm
gtkmm is the official C++ interface for the popular GUI library GTK+. gtkmm is free software distributed under the GNU Lesser General Public License ....


| > !C# and other .NET
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

 languages
| Gtk#
Gtk Sharp
Gtk# is a set of .NET bindings for the GTK+ GUI toolkit and assorted GNOME libraries. The library facilitates building graphical GNOME applications using Mono or any other compliant CLR...


| style="text-align:center;" | Partial support up to 2.20> ! D
D (programming language)
The D programming language is an object-oriented, imperative, multi-paradigm, system programming language created by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is mainly influenced by that language, it is not a variant of C++...


| gtkD
GtkD
In computer programming, GtkD is a language binding of the GTK+ widget toolkit for the D programming language. As of 2011, the latest version is 1.4.1 which wraps GTK+ 2.20...


| style="text-align:center;" | Partial support up to 2.22 (plus Cairo, Gda, Gl, GStreamer)> ! Erlang
| gtkNode
| style="text-align:center;" | Partial support up to 2.16> !GOB
GObject
The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability...


| languages written for the GObject
GObject
The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability...

 system.
| > !Gambas
Gambas
Gambas is the name of an object-oriented dialect of the BASIC programming language as well as the integrated development environment that accompanies it. Designed to run on Linux and other Unix-like computer operating systems, its name is a recursive acronym for Gambas Almost Means Basic...


| gambas2-gb-gtk
| > !Genie
Genie (programming language)
Genie is a modern, general-purpose high-level programming language in active development since 2008. It was designed as an alternative, simpler and cleaner dialect for the Vala compiler, while preserving the same functionality of the Vala language. Genie uses the same compiler and libraries as...


| languages written for the GObject
GObject
The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability...

 system.
| > ! Haskell
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...


| gtk2hs
| > ! Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...


| gtk-fortran
| style="text-align:center;" | Partial support up to 2.24 & 3.0> ! FreeBASIC
FreeBASIC
FreeBASIC is a free/open source , 32-bit BASIC compiler for Microsoft Windows, protected-mode DOS , Linux, FreeBSD and Xbox....


| GladeToBac
| style="text-align:center;" | Supports all versions from 2.8 to 3.0> ! FreePascal
| (header) integrated into the core distribution
| style="text-align:center;" | GTK 2.16 with partial support of later versions> ! Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...


| java-gnome
Java-gnome
java-gnome is a set of language bindings for the Java programming language for use in the GNOME desktop environment. It is part of the official GNOME language bindings suite and provides a set of libraries allowing developers to write computer programs for GNOME using the Java programming language...


| style="text-align:center;" | Partial support up to 2.20 (not available on Windows)> ! JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....


| seed
Seed (programming)
Seed is a JavaScript interpreter and a library of the GNOME project to create standalone applications in JavaScript. It uses the JavaScript engine JavaScriptCore of the WebKit project. It is possible to easily create modules in C....

/GJS
| > ! Lua
| lgob
| style="text-align:center;" | Supports all versions from 2.16> ! Lua
| LuaGtk
| style="text-align:center;" | Partial support up to 2.16> ! Ocaml
| LablGTK
| style="text-align:center;" | Partial support up to 2.16> ! Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...


| Gtk2-Perl
Gtk2-perl
Gtk2-Perl is a set of wrappers for the Perl programming language around the GTK+ GUI library and the other GNOME platform libraries. GTK2-Perl is free software and licensed under the LGPL...


| style="text-align:center;" | Partial support up to 2.20> ! PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...


| PHP-GTK
PHP-GTK
PHP-GTK is a set of language bindings for PHP which allow GTK+ GUI applications to be written in PHP. PHP-GTK provides an object-oriented interface to GTK+ classes and functions.- History:...


| style="text-align:center;" | Partial support up to 2.20> ! Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...


| PyGTK
PyGTK
PyGTK is a set of Python wrappers for the GTK+ graphical user interface library. PyGTK is free software and licensed under the LGPL. It is analogous to PyQt and wxPython which are python wrappers for Qt and wxWidgets respectively. Its original author is the prominent GNOME developer James Henstridge...

 (native as of GTK3)
| > ! R
R (programming language)
R is a programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians for developing statistical software, and R is widely used for statistical software development and data analysis....


| RGtk2
RGtk2
RGtk+ is a set of R wrappers for the GTK+ graphical user interface library. RGtk+ is free software and licensed under the GPL.- Syntax :The code below will produce a 200x200 pixel window with the words "Hello World" inside.librarycreateWindow...


| style="text-align:center;" | Partial support up to 2.12> ! Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...


| ruby-gtk2
| > ! Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...


| Smalltalk GTK
| style="text-align:center;" | GNU Smalltalk
GNU Smalltalk
GNU Smalltalk is an implementation of the Smalltalk programming language by the GNU Project.The implementation, unlike other Smalltalk environments, uses text files for program input and interprets the contents as Smalltalk code...

, Smalltalk YX
Smalltalk YX
Smalltalk YX is an open source programming language. It's an implementation of the Smalltalk-80 standard.Syx is written in the C programming language and has the following purposes:* Readable code* Flexibility through easy creation of plugins...

, Squeak
Squeak
The Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...

> ! Tcl
| Gnocl
| > ! Vala
Vala (programming language)
Vala is a programming language created with the goal of bringing modern language features to C, with no added runtime needs and with little overhead, by targeting the GObject object system. It is being developed by Jürg Billeter and Raffaele Sandrini. The syntax borrows heavily from C#...


| languages written for the GObject
GObject
The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability...

 system.
| >

GUI designers


There were several attempts to create a GUI designer for GTK+. The following projects are active as of July 2011:
  • Glade
    Glade Interface Designer
    Glade Interface Designer is a graphical user interface builder for GTK+, with additional components for GNOME. In its third version, Glade is programming language–independent, and does not produce code for events, but rather an XML file that is then used with an appropriate binding .Glade is...

    , supports GtkBuilder, which is a GTK+ built-in GUI description format.
  • Crow Designer, relies on its own GuiXml format and GuiLoader library.
  • Stetic
    Stetic
    Stetic is a GTK# GUI designer used in MonoDevelop to develop Forms, or windows, to run on the Mono implementation of the Microsoft.NET framework. It has been included since version 0.1 of Monodevelop. Stetic is very similar to Glade Interface Designer but is integrated into Monodevelop with...

    , part of MonoDevelop, oriented towards Gtk#
    Gtk Sharp
    Gtk# is a set of .NET bindings for the GTK+ GUI toolkit and assorted GNOME libraries. The library facilitates building graphical GNOME applications using Mono or any other compliant CLR...

    .

History


GTK+ was originally designed and used in the GNU Image Manipulation Program
GIMP
GIMP is a free software raster graphics editor. It is primarily employed as an image retouching and editing tool and is freely available in versions tailored for most popular operating systems including Microsoft Windows, Apple Mac OS X, and Linux.In addition to detailed image retouching and...

 (GIMP) as a replacement of the Motif
Motif (widget toolkit)
In computing, Motif refers to both a graphical user interface specification and the widget toolkit for building applications that follow that specification under the X Window System on Unix and other POSIX-compliant systems. It emerged in the 1980s as Unix workstations were on the rise, as a...

 toolkit; at some point Peter Mattis
Peter Mattis
Peter Mattis is a computer programmer most notable for his early work on the GNU Image Manipulation Program .In 1995, while students at the University of California at Berkeley, Mattis and his classmate Spencer Kimball developed the first version of The GIMP as a class project...

 became disenchanted with Motif and began to write his own GUI toolkit called the GIMP toolkit and had successfully replaced Motif by the 0.60 release of GIMP. Finally GTK was re-written to be object oriented and was renamed GTK+. This was first used in the 0.99 release of GIMP.

The GTK+ 2.0.0 release series introduced new features which include improved text rendering using Pango
Pango
Pango is an LGPL licensed open source computing library used by software developers for laying out and rendering text in high quality, emphasising support for multilingual text...

, a new theme engine, improved accessibility using the Accessibility Toolkit
Accessibility Toolkit
In computing, Accessibility Toolkit refers in particular to the GNOME ATK.The GNOME ATK, a developer toolkit, allows programmers to use common GNOME accessibility features in their applications. This includes such features as high-contrast visual themes for the visually impaired and keyboard...

, complete transition to Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

 using UTF-8
UTF-8
UTF-8 is a multibyte character encoding for Unicode. Like UTF-16 and UTF-32, UTF-8 can represent every character in the Unicode character set. Unlike them, it is backward-compatible with ASCII and avoids the complications of endianness and byte order marks...

 strings, and a more flexible API. Starting with version 2.8, GTK+ 2 depends on the Cairo
Cairo (graphics)
cairo is a software library used to provide a vector graphics-based, device-independent API for software developers. It is designed to provide primitives for 2-dimensional drawing across a number of different backends...

 graphics library for rendering vector graphics in GTK+ 2.

GTK+ version 3.0.0 included revised input device handling, support for themes
Theme (computing)
In computing, a theme is a preset package containing graphical appearance details, used to customize the look and feel of an operating system, widget set or window manager....

 written with CSS
Cascading Style Sheets
Cascading Style Sheets is a style sheet language used to describe the presentation semantics of a document written in a markup language...

-like syntax, and the ability to receive information about other opened GTK+ applications.
Release series Initial release date Major enhancements Latest minor version
1.0 14 April 1998 First stable version 1.0.6
1.2 27 February 1999 New widgets (GtkFontSelector, GtkPacker, GtkItemFactory, GtkCTree,
GtkInvisible, GtkCalendar, GtkLayout, GtkPlug, GtkSocket)
1.2.10
2.0 11 March 2002 GObject, Universal Unicode UTF-8 2.0.9
2.2 22 December 2002 Multihead support 2.2.4
2.4 16 March 2004 New widgets (GtkFileChooser, GtkComboBox, GtkComboBoxEntry,
GtkExpander, GtkFontButton, GtkColorButton)
2.4.14
2.6 16 December 2004 New widgets (GtkIconView, GtkAboutDialog, GtkCellView).
The last to support Windows 98
Windows 98
Windows 98 is a graphical operating system by Microsoft. It is the second major release in the Windows 9x line of operating systems. It was released to manufacturing on 15 May 1998 and to retail on 25 June 1998. Windows 98 is the successor to Windows 95. Like its predecessor, it is a hybrid...

/ME.
Windows Me
Windows Millennium Edition, or Windows Me , is a graphical operating system released on September 14, 2000 by Microsoft, and was the last operating system released in the Windows 9x series. Support for Windows Me ended on July 11, 2006....

2.6.10
2.8 13 August 2005 Cairo
Cairo (graphics)
cairo is a software library used to provide a vector graphics-based, device-independent API for software developers. It is designed to provide primitives for 2-dimensional drawing across a number of different backends...

 integration
2.8.20
2.10 3 July 2006 New widgets (GtkStatusIcon, GtkAssistant, GtkLinkButton,
GtkRecentChooser) and print support (GtkPrintOperation)
2.10.14
2.12 14 September 2007 GtkBuilder 2.12.12
2.14 4 September 2008 Jpeg2000 load support 2.14.7
2.16 13 March 2009 New GtkOrientable, Caps Lock warning in password Entry.
Improvement on GtkScale, GtkStatusIcon, GtkFileChooser.
2.16.6
2.18 23 September 2009 New GtkInfoBar. Improvement on file chooser, printing.
GDK has been rewritten to use 'client-side windows'
2.18.9
2.20 23 March 2010 New GtkSpinner and GtkToolPalette, GtkOffscreenWindow. Improvement on file chooser,
keyboard handling, GDK.Introspection data is now included in GTK+
2.20.1
2.22 23 September 2010 gdk-pixbuf moved to separate module, most GDK drawing are based on Cairo,
many internal data are now private and can be sealed in preparation to GTK+3
2.22.1
2.24 30 January 2011 New simple combo box widget (GtkComboBoxText) added, the cups print backend can send print jobs as PDF,
GtkBuilder has gained support for text tags and menu toolbuttons and many introspection annotation fixes were added
2.24.5
3.0 10 February 2011 Cairo, more X11 agnostic, XInput2, CSS-based theme API 3.0.12
3.2 25 September 2011 New experimental Wayland and HTML5 backends, New Font Chooser dialog, New widgets: GtkLockButton and GtkOverlay 3.2.0

Future developments


Project Ridley is an attempt to consolidate several libraries that are currently external to GTK+, including libgnome, libgnomeui, libgnomeprint22, libgnomeprintui22, libglade, libgnomecanvas, libegg, libeel, gtkglext, and libsexy.

Developers are also considering new directions for the library, including removing deprecated API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 components and adding an integrated scene graph
Scene graph
A scene graph is a general data structure commonly used by vector-based graphics editing applications and modern computer games. Examples of such programs include Acrobat 3D, Adobe Illustrator, AutoCAD, CorelDRAW, OpenSceneGraph, OpenSG, VRML97, and X3D....

 system, similar to the Clutter
Clutter (computing)
Clutter is an open source graphics library for creating hardware-accelerated user interfaces. It relies upon OpenGL or OpenGL ES for rendering, can be compiled on different platforms and has multiple bindings to other languages...

 graphics library, effectively integrating GTK+ with OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

.

Development and design of the GTK+ 3 release of the toolkit started in February 2009 during the GTK+ Theming Hackfest held in Dublin. A first draft of the development roadmap has been released on 9 April 2009.

GTK+ hello world


The following is a graphical GTK+ hello world
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

 program in the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

. This program has a window with the title "Hello, world!" and a label with similar text.

  1. include


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

gtk_init(&argc, &argv);

/* Create the main, top level window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

/* Give it the title */
gtk_window_set_title(GTK_WINDOW(window), "Hello, world!");

/*
** Map the destroy signal of the window to gtk_main_quit;
** When the window is about to be destroyed, we get a notification and
** stop the main GTK+ loop by returning 0
*/
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

/*
** Assign the variable "label" to a new GTK label,
** with the text "Hello, world!"
*/
label = gtk_label_new("Hello, world!");

/* Plot the label onto the main window */
gtk_container_add(GTK_CONTAINER(window), label);

/* Make sure that everything, window and label, are visible */
gtk_widget_show_all(window);

/*
** Start the main loop, and do nothing (block) until
** the application is closed
*/
gtk_main;

return 0;
}


Using GCC
GNU Compiler Collection
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...

 and pkg-config
Pkg-config
pkg-config is computer software that provides a unified interface for querying installed libraries for the purpose of compiling software from its source code. pkg-config was originally designed for Linux but is now also available for the various BSDs, Microsoft Windows, Mac OS X, and Solaris.It...

 in a Unix shell
Unix shell
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems...

, this code can be compiled with the following command (assume above source has file name "helloworld.c"):


$ gcc -Wall helloworld.c -o helloworld `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`

GTK+ example using Vala instead of C


To create a "Hello World" program in Vala
Vala (programming language)
Vala is a programming language created with the goal of bringing modern language features to C, with no added runtime needs and with little overhead, by targeting the GObject object system. It is being developed by Jürg Billeter and Raffaele Sandrini. The syntax borrows heavily from C#...

 instead of C, do the following:


using Gtk;

int main (string[] args) {
Gtk.init (ref args);

var window = new Window ;
window.title = "Hello, World!";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size (350, 70);
window.destroy.connect (Gtk.main_quit);

var label = new Label ("Hello, World!");

window.add (label);
window.show_all;

Gtk.main;
return 0;
}

Uses


Environments that use GTK+
  • GNOME
    GNOME
    GNOME is a desktop environment and graphical user interface that runs on top of a computer operating system. It is composed entirely of free and open source software...

     is based on GTK+, meaning that programs native to GNOME use GTK+
  • Xfce
    Xfce
    Xfce is a free software desktop environment for Unix and other Unix-like platforms, such as Linux, Solaris, and BSD – though recent compatibility issues have arisen with regard to BSD Unix platforms...

     is based on GTK+
  • LXDE
    LXDE
    LXDE is a free and open source desktop environment for Unix and other POSIX compliant platforms, such as Linux or BSD. The goal of the project is to provide a desktop environment that is fast and energy efficient...

     (Lightweight X11 Desktop Environment) is based on GTK+
  • ROX Desktop
    ROX Desktop
    The ROX Desktop is a graphical desktop environment for the X Window System. It is based on the ROX-Filer which is a drag and drop spatial file manager. It is free software released under the GNU General Public License. The environment was inspired by the user interface of RISC OS...

     is a lightweight desktop, with features from the GUI
    Gui
    Gui or guee is a generic term to refer to grilled dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients. The term derives from the verb, "gupda" in Korean, which literally...

     of RISC OS
    RISC OS
    RISC OS is a computer operating system originally developed by Acorn Computers Ltd in Cambridge, England for their range of desktop computers, based on their own ARM architecture. First released in 1987, under the name Arthur, the subsequent iteration was renamed as in 1988...

  • GPE Palmtop Environment
    GPE Palmtop Environment
    GPE is a graphical user interface environment for handheld computers, such as palmtops and personal digital assistants , running the Linux operating system...

  • Access Linux Platform
    Access Linux Platform
    The Access Linux Platform , once referred to as a "next-generation version of the Palm OS" is an open source-based operating system for mobile devices developed and marketed by Access Co., of Tokyo, Japan. The platform includes execution environments for Java, classic Palm OS, and GTK+-based native...

     (successor of the Palm OS
    Palm OS
    Palm OS is a mobile operating system initially developed by Palm, Inc., for personal digital assistants in 1996. Palm OS is designed for ease of use with a touchscreen-based graphical user interface. It is provided with a suite of basic applications for personal information management...

     PDA
    Personal digital assistant
    A personal digital assistant , also known as a palmtop computer, or personal data assistant, is a mobile device that functions as a personal information manager. Current PDAs often have the ability to connect to the Internet...

     platform)
  • Sugar is a desktop environment oriented on helping children learn, which uses GTK+ and PyGTK
    PyGTK
    PyGTK is a set of Python wrappers for the GTK+ graphical user interface library. PyGTK is free software and licensed under the LGPL. It is analogous to PyQt and wxPython which are python wrappers for Qt and wxWidgets respectively. Its original author is the prominent GNOME developer James Henstridge...

  • KDE
    KDE
    KDE is an international free software community producing an integrated set of cross-platform applications designed to run on Linux, FreeBSD, Microsoft Windows, Solaris and Mac OS X systems...

    , though based on Qt, has integration with GTK+-based programs and themes (since version 4.2).


GTK+ programs do not require a desktop environment
Desktop environment
In graphical computing, a desktop environment commonly refers to a style of graphical user interface derived from the desktop metaphor that is seen on most modern personal computers. These GUIs help the user in easily accessing, configuring, and modifying many important and frequently accessed...

 made with GTK+. If the required libraries are installed, a GTK+ program can run on top of other X11-based desktop environments or window managers; this includes Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 if X11.app
X11.app
XQuartz is Apple Inc.'s version of the X server, a component of the X Window System, for Mac OS X. The current version of XQuartz is a DDX included in the X.Org Server and implements support for hardware-accelerated 2D graphics , hardware OpenGL acceleration and integration with Aqua, the Mac OS...

 is installed (which is the default since the Leopard release). GTK+ can also run under Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

, where it is used by some popular cross-platform applications like Pidgin
Pidgin (software)
Pidgin is an open-source multi-platform instant messaging client, based on a library named libpurple. Libpurple has support for many commonly used instant messaging protocols, allowing the user to log into various services from one application.The number of Pidgin users was estimated to be over 3...

 and GIMP. wxWidgets
WxWidgets
wxWidgets is a widget toolkit for creating graphical user interfaces for cross-platform applications. wxWidgets enables a program's GUI code to compile and run on several computer platforms with minimal or no code changes...

, a cross-platform GUI toolkit, uses GTK+ for Unix-like operating systems. Other ports include DirectFB
DirectFB
DirectFB stands for Direct Frame Buffer. It is a software library for GNU/Linux/Unix-based operating systems with a small memory footprint that provides graphics acceleration, input device handling and abstraction layer, and integrated windowing system with support for translucent windows and...

 (used by the Debian installer
Debian-Installer
Debian-Installer is the installation program for Debian. It was originally written for the Debian 3.1 release , although the first version of a Linux distribution it was used with was Skolelinux Venus ....

, for example) and ncurses
Ncurses
ncurses is a programming library that provides an API which allows the programmer to write text user interfaces in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator...

.

Window managers
The following window managers use GTK+
  • Aewm
  • AfterStep
    AfterStep
    AfterStep is a stacking window manager for the X Window System. The goal of AfterStep's development is to provide for flexibility of desktop configuration, improved aesthetics and efficient use of system resources, and was used in such distributions as MachTen...

  • Amaterus
  • IceWM
    IceWM
    IceWM is a stacking window manager for the X Window System graphical infrastructure, written by Marko Maček. It was coded from scratch in C++ and is released under the terms of the GNU Lesser General Public License...

  • Metacity
    Metacity
    Metacity was the window manager used by default in the GNOME desktop environment until GNOME 3, where it was replaced by Mutter. The development of Metacity was started by Havoc Pennington and it is released under the GNU General Public License....

  • Mutter
    Mutter (window manager)
    Mutter is the window manager for which GNOME Shell is a plugin in GNOME 3, replacing Metacity....

  • Sawfish
    Sawfish (window manager)
    Sawfish is an extensible window manager for the X Window System. Its aim is simply to manage windows in the most flexible and attractive manner possible. Formerly known as Sawmill, the name was changed because another software program had the same name....

  • Wmg
  • Xfwm
    Xfce
    Xfce is a free software desktop environment for Unix and other Unix-like platforms, such as Linux, Solaris, and BSD – though recent compatibility issues have arisen with regard to BSD Unix platforms...


Applications


Some notable applications that use GTK+ as a widget toolkit include:
  • AbiWord
    AbiWord
    AbiWord is a free and open source software word processor. It was originally started by SourceGear Corporation as the first part of a proposed AbiSuite. Development stopped when SourceGear changed their focus to Internet appliances. AbiWord was adopted by some open source developers and AbiWord...

     – Word processor
    Word processor
    A word processor is a computer application used for the production of any sort of printable material....

  • Anjuta
    Anjuta
    Anjuta is an integrated development environment for the C, C++, Java, JavaScript, Python and Vala computer programming languages, written for the GNOME project...

     – Integrated development environment
    Integrated development environment
    An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

     (IDE)
  • Ardour – Digital audio workstation
    Digital audio workstation
    A digital audio workstation is an electronic system designed solely or primarily for recording, editing and playing back digital audio. DAWs were originally tape-less, microprocessor-based systems such as the Synclavier and Fairlight CMI...

  • Chromium
    Chromium (web browser)
    Chromium is the open source web browser project from which Google Chrome draws its source code. The project's hourly Chromium snapshots appear essentially similar to the latest builds of Google Chrome aside from the omission of certain Google additions, most noticeable among them: Google's...

     – Secure web browser
    Web browser
    A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...

     employing WebKit
    WebKit
    WebKit is a layout engine designed to allow web browsers to render web pages. WebKit powers Google Chrome and Apple Safari and by October 2011 held over 33% of the browser market share between them. It is also used as the basis for the experimental browser included with the Amazon Kindle ebook...

     and developed in large part by Google
    Google
    Google Inc. is an American multinational public corporation invested in Internet search, cloud computing, and advertising technologies. Google hosts and develops a number of Internet-based services and products, and generates profit primarily from advertising through its AdWords program...

  • Ekiga
    Ekiga
    Ekiga /i k ai g a/ is a VoIP and video conferencing application for GNOME and Windows. It is distributed as free software under the terms of the GNU General Public License. It was the default VoIP client in Ubuntu until October 2009, when it was replaced by Empathy...

     (formerly GnomeMeeting) – VoIP and video conferencing
    Videoconferencing
    Videoconferencing is the conduct of a videoconference by a set of telecommunication technologies which allow two or more locations to interact via two-way video and audio transmissions simultaneously...

     application
  • Epiphany
    Epiphany (web browser)
    Epiphany is an open source web browser for the GNOME desktop environment. The browser is a descendant of Galeon, and was created after developer disagreements about Galeon's growing complexity...

     – Official GNOME
    GNOME
    GNOME is a desktop environment and graphical user interface that runs on top of a computer operating system. It is composed entirely of free and open source software...

     web browser
  • Evolution – Personal information manager
    Personal information manager
    A personal information manager is a type of application software that functions as a personal organizer. The acronym PIM is now, more commonly, used in reference to Personal information management as a field of study...

  • GIMP
    GIMP
    GIMP is a free software raster graphics editor. It is primarily employed as an image retouching and editing tool and is freely available in versions tailored for most popular operating systems including Microsoft Windows, Apple Mac OS X, and Linux.In addition to detailed image retouching and...

     – Raster graphics editor
    Raster graphics editor
    A raster graphics editor is a computer program that allows users to paint and edit pictures interactively on the computer screen and save them in one of many popular “bitmap” or “raster” formats such as JPEG, PNG, GIF and TIFF....

  • Gnumeric
    Gnumeric
    Gnumeric is a spreadsheet program that is part of the GNOME Free Software Desktop Project. Gnumeric version 1.0 was released December 31, 2001. Gnumeric is distributed as free software under the GNU GPL license; it is intended to replace proprietary and other spreadsheet programs such as Microsoft...

     – Spreadsheet
    Spreadsheet
    A spreadsheet is a computer application that simulates a paper accounting worksheet. It displays multiple cells usually in a two-dimensional matrix or grid consisting of rows and columns. Each cell contains alphanumeric text, numeric values or formulas...

     software
  • GRAMPS
    GRAMPS
    The core export file format of Gramps is named Gramps XML and uses the file extension .gramps. It is extended from XML. Gramps XML is a free format. Gramps usually compresses Gramps XML files with gzip. The file format Portable Gramps XML Package uses the extension .gpkg and is currently a .tar.gz...

     – Genealogy software
    Genealogy software
    Genealogy software is computer software used to record, organize, and publish genealogical data. At a minimum, genealogy software collects the date and place of an individual's birth, marriage, and death, and stores the relationships of individuals to their parents, spouses, and children...

  • Inkscape
    Inkscape
    Inkscape is a free software vector graphics editor, licensed under the GNU General Public License. Its goal is to implement full support for the Scalable Vector Graphics 1.1 standard....

     – SVG
    Scalable Vector Graphics
    Scalable Vector Graphics is a family of specifications of an XML-based file format for describing two-dimensional vector graphics, both static and dynamic . The SVG specification is an open standard that has been under development by the World Wide Web Consortium since 1999.SVG images and their...

     Vector graphics editor
    Vector graphics editor
    A vector graphics editor is a computer program that allows users to compose and edit vector graphics images interactively on a computer and save them in one of many popular vector graphics formats, such as EPS, PDF, WMF, SVG, or VML....

  • LiVES
    LiVES
    LiVES is a free software video editing software and VJ tool, released under the GNU General Public License version 3 or later. There are binary versions available for most popular Linux distributions...

     – Video editor
    Video editing software
    Video editing software, is application software which handles the post-production video editing of digital video sequences on a computer non-linear editing systems...

  • Midori
    Midori (browser)
    is a web browser that aims to be lightweight and fast. It uses the WebKit rendering engine and the GTK+ 2 interface. Midori is part of the Xfce desktop environment's Goodies component...

     – Minimalistic web browser
  • Pidgin
    Pidgin (software)
    Pidgin is an open-source multi-platform instant messaging client, based on a library named libpurple. Libpurple has support for many commonly used instant messaging protocols, allowing the user to log into various services from one application.The number of Pidgin users was estimated to be over 3...

     – Instant messenger
    Instant messaging
    Instant Messaging is a form of real-time direct text-based chatting communication in push mode between two or more people using personal computers or other devices, along with shared clients. The user's text is conveyed over a network, such as the Internet...

  • gconfig – Linux kernel
    Linux kernel
    The Linux kernel is an operating system kernel used by the Linux family of Unix-like operating systems. It is one of the most prominent examples of free and open source software....

     source configuration utility

See also


  • gtkmm
    Gtkmm
    gtkmm is the official C++ interface for the popular GUI library GTK+. gtkmm is free software distributed under the GNU Lesser General Public License ....

     – C++ bindings for GTK+
  • FLTK
    FLTK
    FLTK is a cross-platform GUI library developed by Bill Spitzak and others. Made with 3D graphics programming in mind, it has an interface to OpenGL, but it is also suitable for general GUI programming....

     – A light, cross-platform, non-native widget toolkit
  • FOX toolkit
    FOX toolkit
    The FOX toolkit is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface...

     – A fast, open source, cross-platform widget toolkit
  • Microsoft Foundation Class Library
    Microsoft Foundation Class Library
    The Microsoft Foundation Class Library is a library that wraps portions of the Windows API in C++ classes, including functionality that enables them to use a default application framework...

     (MFC)
  • Object Windows Library
    Object Windows Library
    The Object Windows Library is a Borland C++ object-oriented framework originally designed for WinAPI. It was used in Turbo Pascal for Windows, Borland Pascal and their Borland C++ package. It was a competitor to the Microsoft Foundation Class Library .OWL had incomplete support by the Borland C++...

     (OWL)
  • Qt
  • Ultimate++
    Ultimate++
    Ultimate++ is a C++ cross-platform development framework which aims to reduce the code complexity of typical desktop applications by extensively exploiting C++ features.-Features:* currently supports Microsoft Windows, Linux/X11 and BSD/X11....

  • Visual Component Library
    Visual Component Library
    VCL is a visual component-based object-oriented framework for developing Microsoft Windows applications. It was developed by Borland for use in, and tightly integrated with, its Delphi and C++Builder RAD tools...

     (VCL)
  • wxWidgets
    WxWidgets
    wxWidgets is a widget toolkit for creating graphical user interfaces for cross-platform applications. wxWidgets enables a program's GUI code to compile and run on several computer platforms with minimal or no code changes...

     - cross platform open source C++ widgets toolkit developed by community
  • Widget toolkit
    Widget toolkit
    In computing, a widget toolkit, widget library, or GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces...

  • List of widget toolkits

External links