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