1
-- A simple program to demonstrate Gtk2Hs.
2
module Main (Main.main) where
11
-- Here we connect the "destroy" event to a signal handler.
12
-- This event occurs when we call widgetDestroy on the window
13
-- or if the user closes the window.
14
onDestroy window mainQuit
15
-- Sets the border width and tile of the window. Note that border width
16
-- attribute is in 'Container' from which 'Window' is derived.
17
set window [ containerBorderWidth := 10, windowTitle := "Hello World" ]
18
-- Creates a new button with the label "Hello World".
20
set button [ buttonLabel := "Hello World" ]
21
-- When the button receives the "clicked" signal, it will call the
22
-- function given as the second argument.
23
onClicked button (putStrLn "Hello World")
24
-- Gtk+ allows several callbacks for the same event.
25
-- This one will cause the window to be destroyed by calling
26
-- widgetDestroy. The callbacks are called in the sequence they were added.
28
putStrLn "A \"clicked\"-handler to say \"destroy\""
30
-- Insert the hello-world button into the window.
31
set window [ containerChild := button ]
32
-- The final step is to display this newly created widget. Note that this
33
-- also allocates the right amount of space to the windows and the button.
35
-- All Gtk+ applications must have a main loop. Control ends here
36
-- and waits for an event to occur (like a key press or mouse event).
37
-- This function returns if the program should finish.