Skip to content

Tutorials

vmagnin edited this page May 11, 2022 · 50 revisions

In this section of the documentation, you will find tutorials to get started with gtk-fortran and GTK. Most tutorials are for GTK 4, but with the GTK 3 modifications given when possible.

Our tutorials

External gtk-fortran tutorials

External GTK tutorials

You can also launch the gtk4-demo command (gtk-4-examples package) to run the official GTK examples and read their source code.

The gtk-fortran examples

You can study the examples available in the examples/ directory, beginning by gtkzero_gapp.f90 (just creates an empty GTK window) and gtkhello.f90 (a window with two buttons). Those simple examples are heavily commented in order to help you learn the GTK basics.

Note that in GTK 4, the recommended way to write a GTK program is using GtkApplication like in the gtkzero_gapp.f90 example: in the gtk3 branch, it's the only example using GtkApplication. But if you use GTK 3, try to follow this example for your own programs in order to ease the porting to GTK 4.

If you want to draw progressively a picture pixel by pixel during a scientific computation, mandelbrot_pixbuf.f90 is a good starting point. You can even simply create a PNG file without creating any GUI, by using the GdkPixbuf library: see pixbuf_without_gui.f90.

Clone this wiki locally