[Tkinter-discuss] Tkinter question

Fredrik Lundh fredrik at pythonware.com
Mon Oct 23 20:14:35 CEST 2006

Sorin Schwimmer wrote:

> Is it possible to have a widget id while it is created?

no, because the arguments to the constructor are evaluated *before* the 
constructor is called.

> Something like this:
> Button(root, text='...', command= lambda v=<widget id>: fn(v)).grid()

use lexical scoping:

   b = Button(root, text='...', command=lambda: fn(b))

or, if you're doing this in a loop:

   b = Button(root, text='...')
   b.config(command=lambda b=b: fn(b))


More information about the Tkinter-discuss mailing list