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-fortran is distributed under GNU GPL 3 license.
GTK+ is a free software cross-platform graphical library available for Linux, Unix, Windows and Mac OS X. And gtk-fortran offers currently an interface to more than 9400 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, BSD, 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.
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
If you have an older version of GTK+ 2 or GTK+ 3, you will have no problem because deprecated functions will be removed only in the next major version. With glib, deprecated functions are sometimes removed from one minor version to another.
cmakebuild system if plplot libraries and module files are found on the system, a tutorial on using plplot and gtk-fortran is under construction. Plplot integration
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): you need gfortran 4.6 or higher. Recent Linux distributions come with it.
To download all the project files, you can simply clone the repository using git (see git-basics). Alternatively you can 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.pl perl script can be useful to find which GTK+ functions are used in your programs (see advices to lower compilation time).
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
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.
You will need:
You can install the dependencies manually or you can use the win32_install.bat script (only in the testwin32gtk* branches) for a semiautomatic installation (except PLplot). The latter requires only wget (http://gnuwin32.sourceforge.net/packages/wget.htm) and PLplot to be installed manually.
Windows binaries of PLplot are not distributed. Therefore you have to build your own binaries (after installation of MinGW and Cmake):
cmake -DCMAKE_INSTALL_PREFIX=<installation directory> -DCMAKE_C_COMPILER=gcc -G "MinGW Makefiles" ..(be careful to use NO space in
<installation directory>, e.g. C:\Program Files\PLplot will not work!!!)
<installation directory>\lib\plplot5.9.9\driversdto PATH
<installation directory>\lib\pkgconfigto PKG_CONFIG_PATH
gtk-fortran was successfully tested on the following Windows platforms:
You can also use the (unmaintained) test.bat script to compile all the libraries and examples.
The gtk-fortran developers are mainly working under linux, so do not expect excessive support. If you are a Windows developer, your help would be highly appreciated.
The best way is to use CMake: follow the instructions of the "INSTALL" file. If you do not have CMake, you can alternatively use the test.sh bash script to compile all the library and all examples using gfortran (there is also test95.sh for g95, but it is not maintained).
Use CMake via win32_install.bat or alternatively the (unmaintained) test.bat script to compile all the libraries and examples (more details in the installation section).
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 9000 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.pl perl script can scan your Fortran source files for GTK+ and related library functions and generate the required USE statements. For more informations type:
perl usemodules.pl --help
Note also that the compilation time with gfortran 4.6 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 wiki documentation is under the GNU Free Documentation License 1.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.