This window contains a single button. The button fills the entire window. It is labelled "Click here". When it is clicked the first time, the button label changes to "Hi".
Archive file with this example: Bttn-Example001.tar.gz. Be sure to read the file README.txt for further instructions.
import "gtk3" Graphics.UI.Gtk destroyEventHandler :: IO () destroyEventHandler = do mainQuit buttonClickHandler :: Button -> IO () buttonClickHandler bttn = do buttonSetLabel bttn "Hi" main :: IO () main = do initGUI window <- windowNew button <- buttonNewWithLabel "Click here" set window [windowDefaultWidth := 250, windowDefaultHeight := 200, windowWindowPosition := WinPosCenter, containerChild := button] on button buttonActivated (buttonClickHandler button) on window objectDestroy destroyEventHandler widgetShow button widgetShow window mainGUI
To enable your program to process a button click, you have to do two things:
The button handler is not difficult to understand:
It assigns a new label text to the button.
The connection between the button and its event handler is established with the statement:
on button buttonActivated (buttonClickHandler button)
Note that
(buttonClickHandler button)
is a function call that returns a parameterless function with result type:
IO ()
This is due to currying.