[Tutor] disabling Pmw ComboBox's EntryField? [quick lambda hacks]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 18 Feb 2002 19:18:15 -0800 (PST)

On Mon, 18 Feb 2002, Lance E Sloan wrote:

> Danny Yoo wrote:
> [...]
> > implies that self.cboxDomain.invoke() doesn't need to take the 'event'
> > parameter that get's passed when we bind it to Button-1.  We can do a
> > quicky thing to allow it to ignore the event parameter:
> [...]
> > The above fix may not work perfectly yet.  If you're using a Python older
> > than 2.2, you may need to do something to simulate lexical sope, perhaps
> > something like this:
> > 
> > ###
> > self.cboxDomain.component('entryfield_entry').bind('<Button-1>',
> > lambda event,
> > self=self: self.cboxDomain.invoke())
> > ###

By the way, we don't really need lambda; I was using a shortcut.  We could
alternatively do something like this:

def callback(ignored_event, component=self.cboxDomain):


Python allows us to define functions anywhere; Python's lambda statement
is just a shortcut to avoid giving the function a name.

> This second method worked for me.  I'm using Python 2.1 for now.  I
> assume that will continue to work in future versions of Python for a
> while, too.  Is that correct?

Yes, I'm pretty sure that this will work for a long time; it depends on a
function's default arguments, and I'm pretty sure that won't break at
least until Python 3k or so.  *grin*

> Is there a mailing list somewhere that's dedicated to Python Tkinter
> programming?

Dunno about this, but Tutor is a pretty good place to ask Tkinter
questions.  I believe that Manning, publishers of "Python and Tkinter
Programming", hosts a forum for people who have bought the book:


Good luck!