- 论坛徽章:
- 0
|
问题已解决。谢谢大家:)
通过在事件处理函数中使用print dir(event),可以看到下面这么些属性和方法:
['Checked', 'Clone', 'Destroy', 'GetClassName', 'GetClientData', 'GetClientObject', 'GetEventObject', 'GetEventType', 'GetExtraLong', 'GetId', 'GetInt', 'GetSelection', 'GetSkipped', 'GetString', 'GetTimestamp', 'IsChecked', 'IsCommandEvent', 'IsSelection', 'ResumePropagation', 'SetClientData', 'SetClientObject', 'SetEventObject', 'SetEventType', 'SetExtraLong', 'SetId', 'SetInt', 'SetString', 'SetTimestamp', 'ShouldPropagate', 'Skip', 'StopPropagation', '__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'this', 'thisown']
猜测其中红色那个也许能满足我的要求,一试果然:)python的自省能力太强了,呵呵
通过event.GetEventObject()方法得到触发事件的部件,再通过其GetName()方法即可得到它的name属性(因为我的下一个部件是要通过递增name值来取得)。以后一定好好研究下剩下的,呵呵。
另外,FindWindowById()方法在wxpython in action中有讲述,还有FindWindowByName()和FindWindowByLabel(),这三个方法都能够通过某些已知的属性获得特定的部件,很是方便。这里也可以用楼上所说的GetId()方法获得事件源的id,再利用FindWindowById查找事件源,不过感觉这样多做了一步,还是上面的方法简洁^_^
[ 本帖最后由 琳琳的小狗 于 2006-5-30 10:17 编辑 ] |
|