Haskell/解決方案/GUI
外觀
| 練習 |
|---|
|
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,它可以是Horizontal或Vertical。我正在使用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- 用於建立螢幕截圖中所示的完整佈局的函式

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 ()