当我点击listBoxRow时,我正在尝试打印标签文本。
这是我的要点的链接:https://gist.github.com/bigos/6cf02ff27231cfc0352394da00023f67
相关代码如下所示:
_ <- onListBoxRowSelected listbox2 (\(Just r) -> do
-- rn <- listBoxRowGetIndex r
cc <- containerGetChildren r
dd <- widgetGetName (head cc)
-- how do I print label text?
-- I get the error:
-- Required ancestor ‘GI.Gtk.Objects.Label.Label’ not found for type GI.Gtk.Objects.Widget.Widget’.
ee <- labelGetText (head cc)
putStrLn ("Clicked " ++ (show ee)))
•找不到类型的祖先'GI.Gtk.Objects.Label.Label' “GI.Gtk.Objects.Widget.Widget”。 •在&#39; do&#39;块:ee&lt; - labelGetText(head cc)在表达式中: 做{cc&lt; - containerGetChildren r; ee&lt; - labelGetText(head cc); putStrLn(&#34; Clicked&#34; ++(show ee))}在'onListBoxRowSelected'的第二个参数中,即
https://hackage.haskell.org/package/gi-gtk-3.0.18/docs/doc-index.html
答案 0 :(得分:0)
Dan Robertson提供了最有帮助的答案。获取标签对象后,必须将其转换为Label类型。这是缺失的环节。
_ <- onListBoxRowSelected listbox2 (\(Just r) -> do
cc <- containerGetChildren r
mlabel <- castTo Label (head cc)
case mlabel of
Nothing -> putStrLn "Not a label!"
Just label -> (labelGetText label) >>= putStrLn . unpack)
非常感谢你的帮助。