跳轉到內容

Haskell/解決方案/GUI

來自華夏公益教科書

← 返回 GUI

練習
  1. 新增一個複選框控制元件。它目前不需要做任何事情,只需確保它在使用行佈局時出現在靜態文字和按鈕旁邊,或者在使用列布局時出現在它們下方。文字也是複選框的一個屬性。
  2. 請注意接受一個佈局列表,並生成一個佈局本身。使用此功能,讓您的複選框出現在靜態文字和按鈕的左側,靜態文字和按鈕在列中。
  3. 您能弄清楚單選按鈕控制元件是如何工作的嗎?使用前一個練習的佈局,在複選框、靜態文字和按鈕下方新增一個帶有兩個(或更多)選項的單選按鈕。使用文件!
  4. 使用boxed組合器在四個控制元件周圍建立一個漂亮的外框,並在靜態文字和按鈕周圍建立另一個外框。(注意:boxed組合器可能在 MacOS X 上不起作用 - 您可能會遇到無法互動的視窗小部件。這可能是 wxhaskell 中的一個錯誤。


1. gui- 帶有複選框、行佈局的函式。(替換以獲得列布局)

gui :: IO ()
gui = do
  f <- frame [ text := "Hello World!" ]
  st <- staticText f [ text := "Hello StaticText!" ]
  b <- button f [ text := "Hello Button!" ]
  cb <- checkBox f [ text :=  "Hello Checkbox!" ]
  set f [ layout := row 5 [ widget st, widget b, widget cb ] ]

2. gui- 帶有巢狀佈局組合器的函式。

gui :: IO ()
gui = do
  f <- frame [ text := "Hello World!" ]
  st <- staticText f [ text := "Hello StaticText!" ]
  b <- button f [ text := "Hello Button!" ]
  cb <- checkBox f [ text := "Hello Checkbox!" ]
  set f [ layout := row 5
          [ widget cb
          , column 25
            [ widget st
            , widget b
            ]
          ]
        ]

3. gui- 帶有單選按鈕控制元件的函式。的文件radioBox函式指出建立一個新的單選按鈕組,帶有初始方向和標籤列表。如文件所示Orientation,它可以是HorizontalVertical。我正在使用Vertical這裡,但它並不重要。

gui :: IO ()
gui = do
  f <- frame [ text := "Hello World!" ]
  st <- staticText f [ text := "Hello StaticText!" ]
  b <- button f [ text := "Hello Button!" ]
  cb <- checkBox f [ text :=  "Hello Checkbox!" ]
  rb <- radioBox f Vertical ["Hello Option 1!", "Hello Option 2!" ] [ text := "Hello Radiobox!" ]
  set f [ layout := column 5
          [ row 5
            [ widget cb
            , column 25
              [ widget st
              , widget b
              ]
            ]
          , widget rb
          ]
        ]
  return ()

4. gui- 用於建立螢幕截圖中所示的完整佈局的函式

最終結果(winxp)
gui :: IO ()
gui = do
  f <- frame [ text := "Hello World!" ]
  st <- staticText f [ text := "Hello StaticText!" ]
  b <- button f [ text := "Hello Button!" ]
  cb <- checkBox f [ text := "Hello Checkbox!" ]
  rb <- radioBox f Vertical ["Hello Option 1!", "Hello Option 2!" ] [ text := "Hello Radiobox!" ]
  set f [ layout := boxed "Hello Box 1" $ column 5
          [ row 5
            [ widget cb
            , boxed "Hello Box 2" $ column 25
              [ widget st
              , widget b
              ]
            ]
          , widget rb
          ]
        ]
  return ()
華夏公益教科書