Note: the new cabal packages as of yet do not contain any demos. You can download our demo programs from the repository.
- glib package, version 0.12.3 (current)
- gio package, version 0.12.3 (current)
- cairo package, version 0.12.3 (current)
- pango package, version 0.12.3 (current)
- gtk package, version 0.12.3 (current)
- version 0.11.0
- version 0.9.13
- version 0.9.12
- glib package, version 0.11.0
- gio package, version 0.11.0
- cairo package, version 0.11.0
- pango package, version 0.11.0
- gtk package, version 0.11.0
- version 0.10.0
- version 0.9.13
- version 0.9.12
The API reference can also be built from the source distribution.
You can now search the online API documentation using Hoogle by adding “+gtk” to your query (or “+cairo”, etc.). Hoogle allows you to search by name and by type.
When our documentation is not enough you can refer to the documentation for the underlying C library.
- Glade Tutorial
- step-by-step introduction to using the Glade interface designer with Gtk2Hs to quickly build working and visually-attractive GUIs
We are interested in expanding the range of tutorials. We would very much like to encourage people to help with this. See the development page for details of how to get the sources and send in changes (either via darcs or just via email).
There is an introductory article by Kenneth Hoste (and corresponding sources) that appeared in the first issue of The Monad.Reader. The article demonstrates various Gtk2Hs features (including the use of Glade) through the development of a version of the “memory” card game.
There are also several small demo programs to look over in the demo/ directory in the source distribution.
Help and Frequently Asked Questions
There is a small collection of FAQs.
There is a mailing list for general discussion: firstname.lastname@example.org.
Note that you have to join the mailing list before you can post.
If you use IRC, you may be able to find someone to ask on #haskell on irc.freenode.net.
Hello World in Haskell with Gtk2Hs
To get a feel of how a simple Gtk program written in Haskell looks like, consider the “Hello World” example from the demo/ directory, that comes with Gtk2Hs:
Build this using:
All operations on the GUI are executed in the I/O monad which is not very functional, but easy to understand. It should be possible to guess from the function names what this code does. There are also some special bits:
- The UI elements of Gtk+ (so-called widgets) form a big tree of objects that inherit from each other. In this example,
windowinherits from a class called container wich in turn inherits from a class called
widget. The function
onDestroytakes a widget as argument, in this case we use the more derived
- Widgets have attributes that can be set with a list notation. In the example we
containerBorderWidthattribute of the object
window. Note that
containerBorderWidthis an attribute of the
containerclass from which
windowis derived. It is possible to mix different attributes, e.g. one could set the attribute
windowTitleto, say, “Hello World”.
onDestroyfunctions are used to attach IO actions to so-called signals. A signal is raised when the user undertakes a given action. As shown for
onClicked, it is possible to attach several actions to the same signal. To commuincate with such an IO action,
IORefs can be used.
- Gtk+ determines the layout of UI elements by nesting elements into each other. The size of a window, for example, is determined by the size of the widget that is added to it. In our example, it is determined by the size of the button, which, in turn, is determined by the size of the label “Hello World”.