By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

How to make Python identify GUI buttons by their label

P: n/a
The contractor we hired told us that Python can only recognize GUI objects, specifically buttons, by their ID. This is very inconvenient and hard to work with as the button IDs change a lot between builds. Instead, I want to reference a button by its label like "Save", "Preview", or "Submit." Does anyone know how I can accomplish this?

We use ActiveState ActivePython (32 bit), wxPython, and PyScripter 2.3.3.

Thx in advance,
Nov 8 '10 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,851
I would say your contractor may be right, assuming he means assigning the GUI object to a descriptive identifier instead of the literal ID (masterframe vs. .18497168). I don't know much about wxPython though. In Tkinter, you can access the widgets of a master widget with widget method winfo_children(), iterate on the GUI objects, access each object's options dictionary with configure() and look for a text attribute with the appropriate value. That seems like too much work to me.

Maybe you should consider refactoring your code so it would be easier to maintain between builds.
Nov 10 '10 #2

P: 332
That is pretty much how WxPython works. Check the Window Identifier (A button is a Window in WxPython)section at to get a better idea.
There is a method GetID() that allows to retreive the id of widgets. So I don't know how that would be a show stopper. There are also standard identifiers like WX_EXIT, EX_SAVE.
Ultimately, you can always map your labels to their ID in a dictionary. But I would let WxPython do its business logic...
Nov 10 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.