Gtk 的 Hello World

這個例子展示瞭如何在 Gtk3 中建立一個簡單的 Hello World,設定一個視窗和按鈕小部件。示例程式碼還將演示如何在視窗小部件上設定不同的屬性和操作。

module Main (Main.main) where

import Graphics.UI.Gtk

main::IO ()
main = do
  initGUI
  window <- windowNew
  on window objectDestroy mainQuit
  set window [ containerBorderWidth := 10, windowTitle := "Hello World" ]
  button <- buttonNew
  set button [ buttonLabel := "Hello World" ]
  on button buttonActivated $ do
    putStrLn "A \"clicked\"-handler to say \"destroy\""
    widgetDestroy window
  set window [ containerChild := button ]
  widgetShowAll window
  mainGUI -- main loop