【问题标题】:How can I remove widgets from WxHaskell panel如何从 WxHaskell 面板中删除小部件
【发布时间】:2023-03-11 21:52:01
【问题描述】:

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

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,当它更新时我需要摆脱旧控件)。

【问题讨论】:

  • 你试过visible属性吗?

标签: haskell wxwidgets wxhaskell


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多