1
我想在横幅示例中使用类似标题的可重用容器。 (所以它就像一个自定义GroupBox)。因此,我添加到课程中的每个元素应该被添加到类subcontainer中,而不是添加到其自身中。看到下面的代码,我标记了 我只想写下子元素的位置。如何制作自定义容器?
from enaml.widgets.api import *
from enaml.layout.api import *
from enaml.styling import *
enamldef BannerSheet(StyleSheet):
Style:
element = 'Label'
style_class = 'banner'
Setter:
field = 'background'
value = ('lineargradient(x1: 0, y1:0, x2:0, y2:1, '
'stop: 0 #222222, stop: 0.5 #1A1A1A, stop: 1 #111111)')
Setter:
field = 'color'
value = '#FFFFEF'
Setter:
field = 'padding'
value = '5px'
Setter:
field = 'font'
value = '18pt Verdana'
enamldef Banner(Container):
BannerSheet:
pass
padding = 0
alias title : lbl.text
constraints = [lbl.left == left,
lbl.right == right,
con.top == lbl.bottom,
con.bottom<=bottom]
Label: lbl:
name = 'abd'
style_class = 'banner'
Container: con:
pass
enamldef DemoContainer(Container):
padding = 0
Banner: b:
title = 'Bar'
#i want children here to be put into the banner.con container.
#so e.g.
Label:
text = 'This should be below the title label"
您可以扩展“这不工作”,并解释什么时候它工作?此外,你说你想重写'add_child',但在代码中只有'child_added'被覆盖。这是一个错误? – KobeJohn
你说得对,child_add是错误的方法。据我所知,没有add_child。有一个insert_children方法,但调用它会导致解释器崩溃。 – tillsten
我现在更困惑了。请详细解释您在使用您粘贴的代码时会发生什么以及实际发生的情况。 – KobeJohn