How to remove widgets from the WxHaskell panel

My google-fu failed me. How to remove widgets that I added in Panel ()? For example, in the following, I want the controls-panel to become empty again.

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

(I'm trying to create a dynamic graphical interface, and I need to get rid of the old controls when updating it).

+1
source share
1 answer

You can make it invisible and remove from the layout. This does not actually remove it, but dynamically changes the interface:

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
+1
source

All Articles