如何判断哪个FloatSpin在wxPython中触发了EVT_FLOATSPIN事件?

时间:2012-07-05 16:32:16

标签: event-handling wxpython

我想捕获由我的floatspinner触发的FLOATSPIN事件,但我需要知道哪个FloatSpin控件已触发此事件。这是必需的,以便我可以更新字典的值。

FloatSpin控件是基于键:值对的字典创建的。关键是我的FloatSpin控件的uniqueid,值是控件的默认值。我想更新我的字典k:v对,我正在更新的值将来自FloatSpin控件事件。

鉴于以下(剥离)示例,我如何捕获触发事件的控件的唯一ID?

firstFS = FS.FloatSpin(self, -1, min_val=0, max_val=None, increment=1, value=1, agwStyle=FS.FS_RIGHT)
secondFS = FS.FloatSpin(self, -1, min_val=0, max_val=None, increment=1, value=1, agwStyle=FS.FS_RIGHT)

self.Bind(FS.EVT_FLOATSPIN, self.OnFloatSpin)

def OnFloatSpin(self, event):
    floatspin = event.GetEventObject()

1 个答案:

答案 0 :(得分:0)

花了几个小时试图搞清楚但我明白了!

firstFS = FS.FloatSpin(self, -1, min_val=0, max_val=None, increment=1, value=1, agwStyle=FS.FS_RIGHT)
firstFS.SetName('firstFS')  # for example
secondFS = FS.FloatSpin(self, -1, min_val=0, max_val=None, increment=1, value=1, agwStyle=FS.FS_RIGHT)
secondFS.SetName('secondFS')  # for example

self.Bind(FS.EVT_FLOATSPIN, self.OnFloatSpin)

def OnFloatSpin(self, event):
    floatspin = event.GetEventObject()
    floatspinID = event.GetId()  # grab the widgets id that is firing the event
    '''OR'''
    floatspinName = event.GetEventObject().GetName()  # grab the widget name