wxPython: generating event IDs?

Grant Edwards grante at visi.com
Sun Mar 10 01:20:03 EST 2002


I'm trying to figure out a simple way to attach commands to
buttons in wxPython.  The standard method seems to be

 1) Define a unique ID number
 2) Assign that ID number to the button
 3) Hook a closure to that ID number with EVT_XXXX() 

This seems a bit complicated compared to other toolkits where
you just hook the closure to the button when the button is
created.  I'm sure the wxPython approach has advantages I
haven't stumbled across yet, but all the examples I've found
could have been handled by the simpler method.

There must be a way to eliminate the need to predefine unique
ID numbers.  I hate trying to maintain lists of numbers like
that (well, more accurately, I'm just bad at it).

I tried using id(self.Command), but all of the bound methods of
an object seem to have the same id (as do all of the unbound
methods).  This seems quite weird:

  id(self.x) == id(self.y)  is true
     self.x is self.y       is false  

According to my reading of the language reference, this isn't
possible, since "is" compares the id's of the objects.

I thought about using the id() of the button, but you don't
know that until after the button is created, and you need to 
pass the ID in when the button is created.

There must be a simple solution that I've overlooked...

-- 
Grant Edwards                   grante             Yow!  Do you have exactly
                                  at               what I want in a plaid
                               visi.com            poindexter bar bat??



More information about the Python-list mailing list