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; }