Shanbhag Vinit
Shanbhag Vinit

Reputation: 139

Example of wx.FindWindowByName()

Could you tell me how FindWindowByName works? I couldn't find any example implementing it. I need to identify and open an open frame to append messages to it.I could only find syntax and am having trouble understanding it.Throws unbound method error.I know that this error pops up when a method is called using a wrong object.But I cannot call this method using a wx.Window object as that is what am trying to obtain in the first place....

Upvotes: 1

Views: 807

Answers (1)

RobinDunn
RobinDunn

Reputation: 6206

The main requirement is setting the name of the window, either when it is created by passing name="foo" to its __init__ or by using the SetName("foo") method. Then you can use wx.FindWindowByName to fetch that window later:

>>> import wx
>>> frm = wx.Frame(None, title='FooBar', name='foobar')
>>> frm.Show()
True
>>> 
>>> f = wx.FindWindowByName('busted')
>>> print f
None
>>> f = wx.FindWindowByName('foobar')
>>> print f
<wx._windows.Frame; proxy of <Swig Object of type 'wxFrame *' at 0x1003cdf30> >
>>> print frm
<wx._windows.Frame; proxy of <Swig Object of type 'wxFrame *' at 0x1003cdf30> >
>>> 
>>> f == frm
True
>>> f is frm
True
>>> 

In addition to the the global function used above, there is a static method named FindWindowByName in the wx.Window class that does the same thing, and in earlier versions of wxPython there was a non-static method that only searched the children of the window. So that is probably where the confusion you experienced comes from. Using the global function as shown above should be safe to use in all versions of wxPython however, and if you need to restrict your search to a specific subtree of the containment hierarchy then you can pass the parent window as a second parameter.

Upvotes: 4

Related Questions