Ugly little issue with Tkinter - Pmw.Counter - datatype

Paul Sage psage at ncaustin.com
Fri Mar 29 17:17:39 EST 2002


self._body = Pmw.Counter(parent,
  labelpos = 'w',
  label_text = 'Body:',
  entryfield_value = currentStatBody,
  datatype = lambda s=self, p=thePlayer: s.custom_counter_body(p),
  entryfield_validate = {'validator' : 'integer', 'min' : statMin, 'max'
: statMax})

Basically, I need to pass an object to the function being referenced,
but the lambda solution won't work.  "datatype", in this instance, is
expecting a function name.  The problem is similar to one I had earlier
this week, only this time, datatype assigns implicit arguments to the
function name, and I don't think that is going to fly with lambda.  Any
ideas for how I can reference this object without making it global?

The function header currently looks like this:

def custom_counter_body(self, text, factor, increment):

I need it to look like this:

Def custom_counter_body(self, text, factor, increment, thePlayer)




More information about the Python-list mailing list