我如何从WxHaskell面板中移除小部件 [英] How can I remove widgets from WxHaskell panel
本文介绍了我如何从WxHaskell面板中移除小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的google-fu让我失望了。我如何删除已添加到 Panel()
的小部件?例如,在下面,我希望控件
- 面板再次变空。
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 ()
(我试图构建一个动态GUI,当它更新时,我需要摆脱旧的控件)。
(I'm trying to build a dynamic GUI, and I need to get rid of the old controls when it updates).
推荐答案
您可以使其不可见并将其从布局。这实际上并没有将其删除,但会动态更改用户界面:
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
这篇关于我如何从WxHaskell面板中移除小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文