bittoo1984 has asked for the wisdom of the Perl Monks concerning the following question:

i have a simple gui perl/Tk code. It prints time, date and user-id. Is it possible to configure date variable so that my wnidow keeps updated with time change without any button click

#!/usr/bin/perl use Tk; $ashu="tan"; #color for main window $screen_resolution="800x400+200+100"; #size of main window $mw = new MainWindow(-background=>$ashu); $mw -> geometry($screen_resolution); $mw -> title("VENTURA"); $mw -> Label(-text=>"ventura disk space utilization tracker",-foregrou +nd=>"red",-background=>$ashu,-font=>"{Times New Roman} 20 normal roma +n") -> pack(); $user_id = `whoami`; $date = `date +%d%B%Y`; $time = `date +%T`; #--------------------------------------------------------------------- +---------- $INFO = $mw->Frame(-background=>$ashu)->pack(-side=>'top',-fill=>'both +', -pady=>10); $INFO->Button(-text => "$user_id",-width=>16,-height=>2,-relief=>"flat +",-foreground=>"white",-background=>$ashu,-font=>"{Times New Roman} 1 +0 normal roman")->grid(-row=>0,-column=>0,-padx=>45); $but_date = $INFO->Button(-textvariable => \$date,-command=>\$update_d +ate,-width=>16,-height=>2,-relief=>"flat",-foreground=>"white",-backg +round=>$ashu,-font=>"{Times New Roman} 10 normal roman")->grid(-row=> +0,-column=>1,-padx=>45); $but_time = $INFO->Button(-textvariable => \$time,-command=>\$update_t +ime,-width=>16,-height=>2,-relief=>"flat",-foreground=>"white",-backg +round=>$ashu,-font=>"{Times New Roman} 10 normal roman")->grid(-row=> +0,-column=>2,-padx=>45); #--------------------------------------------------------------------- +---------- MainLoop;

Replies are listed 'Best First'.
Re: realtime time display in perl/Tk ( after repeat)
by Anonymous Monk on Aug 13, 2015 at 10:31 UTC
    Tk::after  $mw->repeat( $ms, sub { $time = gmtime; } );

      Thanks a lot. It worked.