The gtk-fortran project aims to offer scientists programming in Fortran a cross-platform library to build Graphical User Interfaces (GUI). Gtk-fortran is a partial GTK+ / Fortran binding 100% written in Fortran, thanks to the ISO_C_BINDING module for interoperability between C and Fortran, which is a part of the Fortran 2003 standard. GTK+ is a free software cross-platform graphical library available for Linux, Unix, Windows and Mac OS X.
gtk-fortran offers currently an interface to more than 8700 GTK+ 2 and GTK+ 3 functions (GTK, GDK, GdkPixbuf, Cairo, Pango, ATK, GLib, GObject, GIO). These interfaces were automatically created by a python script which parses the C header files of the GTK+ libraries. gtk-fortran has already been tested under Linux, Mac OS X, Windows 7, on 32 bits and 64 bits machines, and on Big-endian and Little-endian machines. See the list of Tested functions and the Status page for more informations. gtk-fortran is distributed under GNU GPL 3 license. The wiki documentation is under the GNU Free Documentation License 1.3.
The second phase of the project is now concentrating on testing and writing examples. You can join our small community to share knowledge, skills and code: just create a github account and you will be able to post messages. Every good will is welcome.
julia_pixbuf.f90 example with gtk-fortran on Ubuntu 11.04
gtk-hl.f90, also demo in
First, you need a Fortran compiler with the ISO_C_BINDING module. If your compiler is compliant with the Fortran 2003 standard, this module should be present. Else you can download gfortran, a free software compiler (see the links at the bottom of this page).
To download all the project files, click on Source (top left), then just below Switch branches to "master" if you use GTK+ 2 or "gtk3" for GTK+ 3, then click on the Downloads button on the right, then choose the .tar.gz or .zip archive depending on your system. The only files you absolutely need are gtk.f90 and the *-auto.f90 files. You can copy them in the same directory as your program or in a specific directory.
gtk-sup.f90 and gtk-hl.f90 are needed for list_demo.f90 and the hl-*.f90 files (see gtk_hl:-A-high-level-interface-for-Gtk-Fortran).
The usemodules.py python script can be useful to find which GTK+ functions are used in your programs (see advices to lower compilation time). Python scripts have been tested under Linux with python 2.6.6 and 2.7.2.
If you use the GNU Fortran compiler, you need gfortran 4.6 or higher. Recent distributions like Fedora 15 and Ubuntu 11.10 come with it. You also need to install the GTK+ development files (Ubuntu example):
sudo apt-get install gfortran libgtk2.0-dev libgtk-3-dev
sudo tar -xzvf gfortran-4.6-20110107-linux-i686.tar.gz -C /
The path to the compiler is then
All the examples were tested under Windows 7 (32 bits) using gfortran 4.6.0 20110115 (experimental) and the dll of GTK+ 2.22.1, put in the src directory. You can use the test.bat batch file.
You can download the all-in-one GTK+ 2.22 bundle at http://www.gtk.org/download/win32.php. More recent versions of some individual libraries (GTK+ 2.24) can be found at http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/.
Note that for high-level examples you need GTK+ 2.18 or higher, and 2.24 for gtkbuilder2.f90 and julia_pixbuf.f90.
The examples were tested under Mac OS X 10.6.7 (Darwin 10.7.0 on x86_64), with the quartz version of GTK2. gtk2 and gfortran 4.6 were built using macports.
See the test.sh bash script to compile all the library and all examples using gfortran (test95.sh for g95).
See the test.bat script to compile all the library and all examples.
Concerning the names of the modules you need, you can generally just look at the beginning of the names of the functions you use: gtk_window_new is in the gtk module, cairo_curve_to is in cairo... Note that all enumerators are currently in the gtk module.
gtk-fortran modules offering interfaces to more than 8000 functions, you should add to your USE statements the ONLY option, e.g.:
use gtk, only: gtk_init, gtk_window_new, GTK_WINDOW_TOPLEVEL, gtk_window_set_title, & & gtk_container_set_border_width, g_signal_connect, gtk_hbox_new, gtk_container_add, & & gtk_button_new_with_label, gtk_box_pack_start, gtk_widget_show, gtk_main, FALSE, & & CNULL, TRUE
The compilation time will be ten times faster than with a simple "use gtk" statement ! To help you, the usemodules.py script can analyze your programs and generate the usemodules.txt file with the USE statements you need. Simply type for example:
python usemodules.py ../examples
But the script does not find all used symbols and you will generally need to complete the USE statements by hand. Note also that the compilation time with gfortran under Windows is ten times longer than under Linux (why ?)
See also the Issues page.
This project is based on Tobias Burnus' post on comp.lang.fortran newsgroup (2nd May 2007 13:10) where he gave a little example of a Fortran 2003 program creating a minimalist GUI (an empty GTK window !) using ISO_C_BINDING. Vincent Magnin posted a message on the 27th December 2010 and got into contact with Jerry DeLisle on the 29th. They launched together the project in January 2011. Other contributors then joined: James Tappin, Jens Hunger...
Gtk-fortran is licensed under GNU General Public License version 3.
The gtk-fortran logo uses the GTK+ logo (by Andreas Nilsson) and so is also under GNU Free Documentation License Version 1.2 or later & Creative Commons Attribution-Share Alike 3.0 Unported license. The font is DejaVu Sans, a font under a free license.