The sidebar entitled "Specifying arguments to callbacks" in Philipp Janert's article Using Advanced Widgets in Perl/Tk (IBM developerWorks) describes the difference in two methods of passing arguments to a -command option for a Tk widget-one fixing the options used at the time the constructor is first executed, the other taking the options at execution time. It may be worth your time to review.
Example code to display the effect
use strict; use warnings; use Tk; my $t = time; my $ts = update_time($t); my $mw = MainWindow->new(); my $label = $mw->Label( -textvariable => \$ts, ) ->grid( -row => 1, -column => 1, -columnspan => 3, ); my %button; # Fixed - will display time when button was created # Variable - will display current time $button{fixed} = $mw->Button( -text => q{Fixed}, -command => [ \&update_time, $t, ], )->grid( -row => 2, -column => 1, ); $button{variable} = $mw->Button( -text => q{Variable}, -command => sub { $t = time; &update_time( $t, ); }, )->grid( -row => 2, -column => 2, ); $button{exit} = $mw->Button( -text => q{Exit}, -command => sub { exit; }, )->grid( -row => 2, -column => 3, ); MainLoop; # subroutines sub update_time { my $ct = shift @_; $ts = sprintf qq{%s}, scalar localtime $ct; }
Hope that helps.
In reply to Re: Passing arguments for GUI development in Tk
by atcroft
in thread Passing arguments for GUI development in Tk
by archana12
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |