Haskell Graphics Library that works in GHCi on MacOS X

前端 未结 5 2023
滥情空心
滥情空心 2021-01-30 07:30

Does there exist a Haskell graphics library or binding to an external library that fulfills the following requirements:

  1. Can be used from ghci, i.e. I
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 07:58

    The Gtk2Hs library fulfills all the requirements if you use the X11 version of the gtk2 framework.

    Concerning the requirements:

    1. Using X11 avoids many problems.
    2. Install gtk2 via MacPorts and use the +x11 option (default). (That said, I've had numerous problems installing gtk2 in the past, but this time it seemed to work.)
    3. I would be surprised if GTK+ can't do that.
    4. Ditto.

    Here a minimal example

    import Graphics.UI.Gtk
    
    hello :: (ButtonClass o) => o -> IO ()
    hello b = set b [buttonLabel := "Hello World"]
    
    main :: IO ()
    main = do
        initGUI
        window <- windowNew
        button <- buttonNew
        set window [windowDefaultWidth := 200, windowDefaultHeight := 200,
                  containerChild := button, containerBorderWidth := 10]
        onClicked button (hello button)
        onDestroy window mainQuit
        widgetShowAll window
        mainGUI
    

提交回复
热议问题