Cyker
Cyker

Reputation: 10994

Why it's not recommended to use IDs in 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?

Upvotes: 4

Views: 2404

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33111

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.

Upvotes: 4

Related Questions