[wxPython-users] Setting the ID for widgets

Christopher Barker Chris.Barker at noaa.gov
Fri Mar 30 10:00:04 PDT 2007


DomDom wrote:
> Until now, I put -1 or wx.NewId() in the widgets' contructors.

I think the cleanest way to do it is to not specify an id at all, and 
use keyword args for the stuff you do need to specify:

MyButton = wx.Button(parent, label="ALabel")

There are a few places where an id must be specified, wx.Menu.Append() 
for instance. IN that case, use:

wx.ID_ANY

(which equals -1, but I think it's clearer and more future proof.)


Chris Mellon wrote:

> in wxPython, I tend to ignore IDs almost totally and simply
> pass the widget itself anywhere I need it.

me too, but if you really do need it:

id = MyButton.GetId()


-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 at noaa.gov




More information about the wxpython-users mailing list