eric_brunel at despammed.com
Tue Oct 24 09:20:20 CEST 2006
On Tue, 24 Oct 2006 07:48:51 +0200, Hendrik van Rooyen
<mail at microcorp.co.za> wrote:
> Sorin Schwimmer wrote:
> Hi All,
> Is it possible to have a widget id while it is created?
> Something like this:
> Button(root, text='...', command= lambda v=<widget id>: fn(v)).grid()
> and then the function:
> def fn(v):
> v['bg']='BLUE' # or maybe nametowidget(v)['bg']='BLUE'
This cannot be done this way: when you create your lambda passed to the
'command' option, the widget itself is not yet created. So there's no way
at all to get the 'id' it will have when created.
Alternatively, you can simply split the widget creation in several lines:
b = Button(root, text='...')
b.configure(command=lambda b=b: fn(b))
But Hendrik's solution is better, since it avoids the use of lambda, which
is often difficult to understand.
python -c "print ''.join([chr(154 - ord(c)) for c in
More information about the Python-list