Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why it's not recommended to use IDs in wxPython?

Tags:

wxpython

I read this Style Guide for wxPython code which says:

3. Don't use IDs. There is very rarely a good reason to use them.

I've also seen a lot of wx.ID_ANY in application code.

Questions:

  1. Why it's not recommended to use IDs?

  2. Why doesn't the library simply hide IDs in the API if they shouldn't be used anyway?

like image 379
Cyker Avatar asked Oct 23 '25 14:10

Cyker


1 Answers

You don't want to use hard-coded IDs because there are some that are reserved by wxPython itself. This is why we have wx.ID_ANY. This allows wxPython to grab an unused ID, which prevents collisions, which also prevents hard to find bugs.

Note that using wx.NewId is now deprecated and you should use wx.Window.NewControlId() in wxPython 4.

like image 110
Mike Driscoll Avatar answered Oct 26 '25 07:10

Mike Driscoll