tcltk-toolkittkx

Perl Tk/Tcl: Can widget callbacks take parameters


Is it possible to create a button, for example, whose callback takes a parameters?

e.g.

button(-text => 'Row1', -command => \&do_something_with('Row 1'));

Tried it on a test program and it doesn't seem to. If that is the case, is there some other way to do what I intend with the example above?

My program needs to create buttons but the number is not known beforehand (depends on a .cfg file).


Solution

  • You probably need an anonymous subroutine that invokes your subroutine with at least one parameter.

    button(-text => 'Row1', -command => sub {do_something_with('Row 1', @_)});