-
Notifications
You must be signed in to change notification settings - Fork 46
Learning from examples
Once you will have created your first gtk-fortran toy applications, you will need to use more widgets and GTK advanced features. Learning by reading and playing with gtk-fortran and GTK examples is a good way.
Let's have a look at some gtk-fortran examples available in the examples/
and plplot/
directories.
Take gtkzero_gapp.f90 as a starting point. It just creates an empty GTK window with around 30 lines of Fortran code:
Then have a look at gtkhello.f90 which opens a window with two buttons. You will see how you can create buttons, arrange them in a box container and link them to callback functions.
These two examples are heavily commented in order to help you learn the GTK basics.
If you want to draw progressively a picture pixel by pixel during a long scientific computation, you should first work on the [[Drawing an image in a PNG file (without GUI)|Tutorial 2] short tutorial to discover the GdkPixbuf library. Then the mandelbrot_pixbuf.f90 will show you how a GdkPixbuf can be drawn on a GtkDrawingArea via Cairo.

The simplest example to learn to make vectorial drawing is the cairo-basics.f90 example, which just open a window and draws lines, circles, bezier curves and text using the Cairo library:
The cairo-tests.f90
example demonstrates it is possible to mix bitmap and vectorial drawing on the same GtkDrawingArea.
When you will feel ready to work on more complicated graphical user interfaces, the julia_pixbuf.f90 will be a good starting point. It combines bitmap drawing, buttons, combo-boxes, spin buttons, grid layout, text view, tabs, etc.

You can also run the gtk4-demo
command (gtk-4-examples
package in Ubuntu) to launch each official GTK example and read directly its C source code.
- Installation
- My first gtk-fortran application
- Drawing an image in a PNG file (without GUI)
- A program also usable without GUI
- Using Glade3 and gtkf-sketcher (GTK 3)
- Using gtk-fortran as a fpm dependency
- Debugging with GtkInspector
- Learning from examples
- Video tutorials
- How to start my own project from a gtk-fortran example
- git basics
- CMake basics
- Alternatives to CMake
- How to migrate to GTK 4
- How to contribute to gtk-fortran
- How to hack the cfwrapper with other C libraries