How can I remove widgets from WxHaskell panel

心已入冬 提交于 2019-12-24 10:17:03

问题


My google-fu has failed me. How can I remove widgets that I've added to a 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 build a dynamic GUI, and I need to get rid of the old controls when it updates).


回答1:


You could make it not visible and remove it from the layout. This doesn't actually remove it but does change the UI dynamically:

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


来源:https://stackoverflow.com/questions/9478767/how-can-i-remove-widgets-from-wxhaskell-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!