Perl Tk/Tcl: Can widget callbacks take parameters

175 views Asked by At

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).

2

There are 2 answers

0
glenn jackman On BEST ANSWER

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', @_)});
0
suku007 On

I failed to understand your question clearly but from what i understood is it something like:

button(-text => 'Row1', -command => \&do_something_with('Row 1'));
ttk::button -text $row -command [list RowOpertaion $row $xyz $abc]

Here RowOperation is a proc with 3 parameters suppose row, abc, xyz. In that proc you can do the needful.