Find a component by name or ID ?

Larry Bates larry.bates at websafe.com
Thu Oct 25 15:32:32 PDT 2007


Bob Klahn wrote:
> At 02:10 PM 10/21/2007, Stef Mientki wrote:
> So the questions are:
>> How can I find a component by it's ID (annd limit the search to a 
>> specified parent) ?
>> How can I find a wx-component, in a specified parent/container, by 
>> it's name ?
> 
> Stef, I find windows by label, and I find that extremely handy.  I 
> simply use .SetLabel('the label') on the windows I need to find, and
> wx.FindWindowByLabel('the label') elsewhere.
> 
> And wx.FindWindowByLabel has a second, optional argument, the "parent"; 
> if present, the search will be limited, as the help text states,  to the 
> given window hierarchy.
> 
> The labels I create reflect the hierarchy of my =data=; the window 
> hierarchy can be completely different.  As needs arise for me to change 
> my applications' layouts, I rarely need to change anything relating to 
> data access.    But you know all that, having used this kind of 
> technique in Delphi.
> 
> FindWindowById and FindWindowByName also exist, and they too carry the 
> second optional argument.  But, for me at least, finding by label is by 
> far the most flexible.  (BTW, FindWindowByName will call 
> FindWindowByLabel if the searched-for name is not found.)
> 
> Bob
> 
> P.S.  I'm curious: how come you switched from Delphi to wxWindows?  I'm 
> guessing it was primarily a financial decision.

Bob,

I have something REALLY odd happening when I try this.  I can FindWindowByLabel 
in one class, but it returns None in another class.  I copied the code from one 
to another so I know it is the same.  I have a single top-level frame (which is 
what I'm trying to get access to).  This seems like it would be so easy.  Any ideas?

Thanks in advance.
Larry





More information about the wxpython-users mailing list