Skip to content


vmagnin edited this page Jun 5, 2011 · 204 revisions

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 around 8800 GTK+ 2.24 and 8450 GTK+ 3.0 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 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.

julia_pixbuf.f90 example with gtk-fortran on Ubuntu 11.04julia_pixbuf.f90 example with gtk-fortran on Ubuntu 11.04

More Screenshots.


  • 06-03-2011: jtappin's RPN Scientific calculator is a good example of what can be done with gtk-fortran.
  • 05-19-2011: Added first version of the GTK+ Fortran code sketcher gtkf-sketcher.
  • 05-07-2011: Added tree widget and also table and notebook containers to gtk-hl.f90.
  • 04-24-2011: Added multi column list to gtk-hl.f90, also demo in examples/hl-list_n.f90.
  • 04-19-2011: Added Wiki page documenting gtk-sup.f90 Supplementary routines
  • 04-19-2011: gtk-fortran is now listed on the GTK+ Language Bindings page.
  • 04-18-2011: Added File Choosers to src/gtk-hl.f90, and demo to examples.
  • 04-18-2011: all examples successfully tested under Windows 7 & GTK+ 2.22.1, except gtkbuilder2.f90 which needs GTK+ 2.24.
  • 04-18-2011: gtk-fortran has been successfully tested on Mac OS X & GTK+ 2.24.4 !
  • 04-13-2011: Added ComboBox interface to gtk-hl.f90.
  • 04-12-2011: Added high-level interfaces for sliders, spin boxes and text view (and example codes).
  • 04-11-2011: gtk-fortran is now GTK+ 3.0 ready ! All the examples compile and run under Linux. See the Gtk3 page.

Older news


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 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.1.


If you use the GNU Fortran compiler, you need gfortran 4.6.0 or higher. After downloading the install file, you can install it by typing something like:

sudo tar -xzvf gfortran-4.6-20110107-linux-i686.tar.gz -C / 

The path to the compiler is then /usr/local/bin/gfortran

You also need the GTK+ development files:

sudo apt-get install libgtk2.0-dev


  • You can also use Fedora 15 which is one of the first distributions to come natively with gfortran 4.6.0 and GTK+ 3.0.9.
  • depending on your installation, you may also need the packages libmpc2 and libmpfr1ldbl.
  • gtk-fortran has also been tested with the compilers:
    • Intel Fortran 12.0.0 on x86-ubuntu-maverick (bdsatish, 02-14-2011).
    • g95 version 0.93, Ubuntu x86_64 (bonanza, 02-17-2011).
    • g95 (2010-06-16 debian version), Ubuntu 10.10, 32 bits (vmagnin).


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 More recent versions of some individual libraries (GTK+ 2.24) can be found at

Note that for high-level examples you need GTK+ 2.18 or higher, and 2.24 for gtkbuilder2.f90 and julia_pixbuf.f90.

Mac OS X

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 bash script to compile all the library and all examples using gfortran ( for g95).


See the test.bat script to compile all the library and all examples.

Advices to lower compilation time

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 script can analyze your programs and generate the usemodules.txt file with the USE statements you need. Simply type for example:

python ../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 ?)

Known issues or limitations

  • Very few GTK+ types are not yet implemented.
  • Macro functions (#define) are not implemented.
  • Structures (struct) are not implemented.
  • gstdio.h and giochannel.h were excluded because some functions are declared twice (UNIX and non UNIX systems for example).
  • 85 functions with optional arguments (variadic fuctions) are not implemented. Some of these functions are also available with an array argument to solve binding problems (for example gtk_list_store_new / gtk_list_store_newv), but not all. See
  • Some enums are still missing, like GdkPixdataType.
  • All enums are in the gtk module. It would be better either to dispatch them in the right modules or to create an enums module.
  • g_signal_connect: should have been be declared as a function returning a c_long (handler_id).
  • Fortran has no unsigned integers, so problems could occur if you pass great values between Fortran and GTK+. See the tests.f90 file.
  • Missing deallocate in gtk_init() ? (g95 message when the program is quited).

See also the Issues page.


How can I help ?

  • We need people compiling and running the examples under various OS, architectures (32/64 bits...) and with various Fortran compilers. You can signal bugs.
  • You can write new examples or improve existing examples and share them with the community. Note that C examples are available in the applications gtk-demo and gtk3-demo (gtk-3-examples and gtk2.0-examples Ubuntu packages).
  • If you have knowledge about GIR format or XML parsing with python, your help can be precious for future versions.
  • You can simply talk to your colleagues of this new possibility of creating Graphical User Interfaces for their Fortran programs.
  • Put a link on your site to, and include the "gui" and "graphical user interface" keywords. It will improve the pagerank of the project in search engines.


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.


  • Why GTK+ rather than Qt or wxWidgets ? We chose GTK+ because it is written in C, so the binding is easier than with C++.
  • Is gtk-fortran only useful for GUI ? No because GTK+ includes the crossplatform GLib library which offers a lot of generic functions (regular expressions, random numbers, hash, strings, input/output...)

Useful links

Tools used in this project

Something went wrong with that request. Please try again.