in reply to Currently selected TK widget.

It's very simple, once you've seen the trick. You will see this type of callback in all sorts of Tk code.
foreach my $button ( @buttons ) { ......... ........ # Add a button widget $frame->Button( -anchor => 'nw', -text => "change " . $button, -command => [\&print_button_label, $button], )->pack( -side => 'left', -anchor => 'w', -padx => 2 ); } ############################################### sub print_button_label{ my $button = shift; print "button\n"; }
There are a few variations on the callback syntax. You could also do
-command => sub { print_button_label( $button ) },

You could also use the 'current' tag trick, where you bind a <1> press to a sub which gets the currently active widget, then use cget on the widget, to find it's name or other property; but you will usually see it as I shown above.


I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Currently selected TK widget.
by Butch (Novice) on Apr 11, 2006 at 11:52 UTC
    Brilliant!

    That's exactly what I need.
    Thanks for the speedy reply.

    Butch.