1

I created a simple haskell program to display a window :

module Main where

import           Graphics.UI.Gtk
import           Graphics.UI.Gtk.Glade

data GUI = GUI {
  mainWin :: Window,
  clickMe :: Button,
  display :: Label
  }

loadGlade :: IO GUI
loadGlade = do
  Just xml <- xmlNew "gladeFile.glade"
  mw <- xmlGetWidget xml castToWindow "wdwFirst"
  bc <- xmlGetWidget xml castToButton "btnClick"
  ld <- xmlGetWidget xml castToLabel "lblDisplay"

  return $ GUI mw bc ld

connectGui :: GUI -> IO  (ConnectId Button)
connectGui gui = do
  onDestroy (mainWin gui) mainQuit
  onClicked (clickMe gui) (guiAnswer gui)

guiAnswer :: GUI -> IO()
guiAnswer gui =
  labelSetText (display gui) "WELCOME!!"


main :: IO ()
main = do
  initGUI
  gui <- loadGlade
  connectGui gui
  mainGUI

with this gui file created by glade:

<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
  <!-- interface-requires gtk+ 2.24 -->
  <!-- interface-naming-policy project-wide -->
  <widget class="GtkWindow" id="wdwFirst">
    <property name="can_focus">True</property>
    <property name="title" translatable="yes">DEBUT</property>
    <property name="window_position">center</property>
    <property name="default_width">400</property>
    <property name="default_height">250</property>
    <child>
      <widget class="GtkLayout" id="layout1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <widget class="GtkButton" id="btnClick">
            <property name="label" translatable="yes">Click me!</property>
            <property name="width_request">100</property>
            <property name="height_request">23</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
          </widget>
          <packing>
            <property name="x">21</property>
            <property name="y">20</property>
          </packing>
        </child>
        <child>
          <widget class="GtkLabel" id="lblDisplay">
            <property name="width_request">350</property>
            <property name="height_request">136</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">gdghh
</property>
          </widget>
          <packing>
            <property name="x">43</property>
            <property name="y">77</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>

the program compiles, and runs without error but...nothing appears, there is no window.

I use glade 3.8.5 with gtk+ 2

thanks

1 Answer 1

1

You have forgotten to actually show the window. A function call like

    widgetShowAll window

seems to be missing.

edit

This main function should work:

    main :: IO ()
    main = do
     initGUI
     gui <- loadGlade
     connectGui gui
     widgetShowAll (mainWin gui)
     mainGUI        
Sign up to request clarification or add additional context in comments.

2 Comments

What do you mean? Is there an actual function widgetShowAll, or is this just a suggestion?
There is a function called widgetShowAll. This minimal example shows the functions you need. (Sadly this tutorial is outdated.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.