-- A simple program which pops up a window saying 'Hello World' with a -- button saying 'Bye' which you click and it changes the message to -- 'Goodbye'. if you click the button again the program exits. -- This is the gtk2hs solution. import Mogul import Control.Concurrent.MVar main :: IO () main = do initGUI -- create a top-level window win <- newWindow -- create a VBox to hold different sized widgets and but it into the window vbox <- newVBox False 5 win `containerAdd` vbox -- create the two UI elements but <- newButtonWithLabel "Bye" lab <- newLabel $ Just "Hello World" -- add them to the VBox such that the button stays the same size and -- that the label spreads out over the available area when resized boxPackStart vbox lab PackRepel 0 boxPackEnd vbox but PackNatural 0 -- add a handler for the button clicked signal stop <- newMVar False but `onClicked` do state <- readMVar stop if state then mainQuit else do lab `labelSetText` "Goodbye" but `buttonSetLabel` "Exit" swapMVar stop True return () -- for completeness: quit the application when the window ceases win `onDestroy` mainQuit -- show and run the demo widgetShowAll win mainGUI