The problem was that gtk2hs does not support gtk3, and the file I created was for gtk3.
Glade can generate a libglade file or a gtkbuilder file. Both are xml files, and the main difference between them is that the first starts with <glade-interface> , and later starts with <interface> . Gtkbuilder files also use the <object> tag instead of the <widget> tag.
The Graphics.UI.Gtk.Glade package uses libglade files, and the problem is that they are outdated and outdated.
Two versions are available on the Glade download page. The newer one is generated by gtkbuilders, designed for use with gtk3, but since gtk2hs does not support gtk3, you will have to download version 3.8, which generates the libglade and gtkbuilder files for gtk2.
It is best to stop using libglade files and use gtkbuilder files instead. To do this, you must import Graphics.UI.Gtk.Builder instead of Graphics.UI.Gtk.Glade
I found this tutorial that uses gtkbuilder instead of libglade.
This program creates a window with a button, and each time you press the button, you get a "hello world" on your terminal until the window is closed.
import Graphics.UI.Gtk import Graphics.UI.Gtk.Builder main = do initGUI builder <- builderNew builderAddFromFile builder "windowbuilder.glade" mainWindow <- builderGetObject builder castToWindow "main_window" onDestroy mainWindow mainQuit helloWorldButton <- builderGetObject builder castToButton "hello_world_button" onClicked helloWorldButton (putStrLn "Hello, World!") widgetShowAll mainWindow mainGUI
This pulls gui from the windowbuilder.glade file. I created this file using glade-3. Here it is.
<?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="2.24"/> <object class="GtkWindow" id="main_window"> <property name="width_request">210</property> <property name="can_focus">False</property> <property name="title" translatable="yes">This is a window</property> <property name="resizable">False</property> <child> <object class="GtkVBox" id="vbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Click the button!!</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="hello_world_button"> <property name="label">gtk-ok</property> <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="border_width">7</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="padding">5</property> <property name="position">1</property> </packing> </child> </object> </child> </object> </interface>
Another good reason to switch to gtkbuilder files is that the haskell firmware package will not compile with ghc> = 7.6.
tokoro
source share