Get Object using Id

Hi,

wx.Button(self, id=3)

Now how do I access this button using id. Something like:

GetObjectById(3).SetName(“myButton”)

Hello,

Search the web its your friend:

http://www.google.com/search?hl=en&q=%22wxPython%22+%22get+object+by+id%22

···

On 8/15/08, Prashant Saxena animator333@yahoo.com wrote:

Hi,

wx.Button(self, id=3)

Now how do I access this button using id. Something like:

GetObjectById(3).SetName(“myButton”)


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

FindWindowById(id)
Accepts an integerBut if you just want to name your button, put the name in the constructor:
wx.Button8self, id = 3, name = ‘myButton’)

···

2008/8/15 Prashant Saxena animator333@yahoo.com

Hi,

wx.Button(self, id=3)

Now how do I access this button using id. Something like:

GetObjectById(3).SetName(“myButton”)


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Prashant Saxena wrote:

wx.Button(self, id=3)

Now how do I access this button using id. Something like:

GetObjectById(3).SetName("myButton")

Yes, you can do that, but I won't tell you how, 'cause I don't think it is a good idea.

1) assigning IDs like that can accidentally cause conflicts -- yes, there are ways around that, but why?

2) hardcoding the same number it two parts of your code is a maintenance mess, and it's ugly.

Which leads you to something like:

self.Button3ID = wx.NewId()
wx.Button(self, id=self.Button3ID)

then, later on:

...FindWindowById(self.Button3ID).SomeMethod(..)

but if you're going to do that, why not just store a reference to the button:

self.Button3 = wx.Button(self, label="A label")

then, later on:

...self.Button3.SomeMethod(..)

I avoid using IDs altogether.

For other style ideas, see:

http://wiki.wxpython.org/wxPython%20Style%20Guide

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov