The following program does not work as expected:
module Main where
import Graphics.UI.Gtk
import Control.Monad.IO.Class (liftIO)
import Control.Concurrent (forkIO)
main = do
unsafeInitGUIForThreadedRTS
window <- windowNew
windowSetDefaultSize window 200 200
label <- labelNew (Just "Hello")
forkIO (postGUISync (containerAdd window label))
on window deleteEvent (liftIO mainQuit >> return True)
widgetShowAll window
mainGUI
The label is not added to the window. I compile with -threaded. Am I doing it wrong?
I believe that widgetShowAll
only shows the children at the time of execution, so if your containerAdd
happens after that, it won't appear. I suggest explicitly showing the label in the action you pass to postGUISync
, like this:
forkIO (postGUISync (containerAdd window label >> widgetShow label))