如何从WxHaskell面板中删除小部件

时间:2012-02-28 08:42:38

标签: haskell wxwidgets wxhaskell

我的google-fu让我失望了。如何删除已添加到Panel ()的小部件?例如,在下面,我希望controls - 面板再次变为空。

buildGUI = do
  f <- frame [ text := "Hello" ]

  controls <- panel f []
  ctext <- staticText controls [ text := "Foo" ]
  set controls [ layout := margin 5 (widget ctext) ]

  set f [ layout := widget controls ]
  {- delete ctext ? How? -}
  return ()

(我正在尝试构建一个动态GUI,我需要在更新时删除旧控件。)

1 个答案:

答案 0 :(得分:1)

您可以使其不可见并将其从布局中删除。这实际上并没有删除它,但会动态更改UI:

import Graphics.UI.WX

buildGUI = do
  f <- frame [ text := "Hello" ]

  controls <- panel f []
  ctext <- staticText controls [ text := "Foo" ]
  butn <- button controls [text := "Remove the Foo"]        -- I've added a button to remove Foo
  set controls [ layout := row 0 [margin 5 (widget ctext),
                                  margin 5 (widget butn) ]]

  set f [ layout := widget controls ]

  set butn [on command := do
      set ctext [visible := False]                          -- so ctext doesn't show
      set controls [layout := margin 5 (widget butn) ]]     -- so ctext doesn't take up space
  return ()

main = start buildGUI