我正在用Python中的Enaml设计一个UI。我有一个自定义控件,包括两个按钮。每次点击这两个按钮中的任何一个,一个是1,另一个是id-ed 2,我希望父容器具有单击哪个按钮的感觉。因此,事件处理程序与父处理程序接受一个额外的参数来区分事件的源。这是我的密码
from enaml.widgets.api import (
Window, Container, PushButton
)
enamldef TwoButtons(Container):
attr cont
PushButton:
text = 'Button1'
clicked :: cont.clicked(1)
PushButton:
text = 'Button2'
clicked :: cont.clicked(2)
enamldef Main(Window):
Container:
attr buttonId
event clicked
TwoButtons:
cont = parent
clicked ::
# A way to read the event handler argument goes here
print "Someone is clicked, don't know who :("有什么建议吗?
谢谢,并致以最良好的问候!
发布于 2015-04-29 13:10:35
从我同事那里得到了一些线索。我们可以使用内置的change字典来跟踪事件。
完整的代码列表:
from enaml.widgets.api import (
Window, Container, PushButton)
enamldef TwoButtons(Container):
attr cont
PushButton:
text = 'Button1'
clicked :: cont.clicked(1)
PushButton:
text = 'Button2'
clicked :: cont.clicked(2)
enamldef Main(Window):
Container:
attr buttonId
event clicked
TwoButtons:
cont = parent
clicked ::
print change.get('value')
print "I know it's you {i:s}".format(s=change['value'])https://stackoverflow.com/questions/29915502
复制相似问题