use Tk; use Tk::DateEntry; my $tl = MainWindow->new(); my $frame = $tl->Frame()->pack(-side=>'left'); my $lab = $frame->Label(-text=>"From")->pack(-side=>'left'); my $ent = $frame->Entry()->pack(-side=>'left'); my $frame1 = $tl->Frame()->pack(-side=>'right'); my $lab1 = $frame1->Label(-text=>"To ")->pack(-side=>'right'); my $ent1 = $frame1->Entry()->pack(-side=>'right'); my $textarea = $tl -> Frame(); my $text = $textarea -> Text(-width=>170 , -height=>30, -font=> "Courier 9 bold", -wrap =>'none'); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $text]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $text]); $text -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]); $text -> grid(-row=>3,-column=>1); $srl_y -> grid(-row=>3,-column=>2,-sticky=>"ns"); $srl_x -> grid(-row=>4,-column=>1,-sticky=>"ew"); $textarea -> grid(-row=>3,-column=>1,-columnspan=>2); #Geometry Management $lab -> grid(-row=>0,-column=>0); $ent -> grid(-row=>0,-column=>1); $frame -> grid(-row=>0,-column=>1,-columnspan=>2); $lab1 -> grid(-row=>1,-column=>0); $ent1 -> grid(-row=>1,-column=>1); $frame1 -> grid(-row=>1,-column=>1,-columnspan=>2); my $push_button1 = sub { print "Hello"; }; my $push_button2 = sub { my $out = calendar(); print $out; #return value here }; my $but1 = $tl->Button( -text => 'Enter', -command => $push_button1 ); my $but2 = $tl->Button( -text => 'Enter', -command => $push_button2 ); my $but3 = $tl->Button( -text => 'Generate Reports', -command => $push_button2 ); $but1 -> grid(-row=>0,-column=>2); $but2 -> grid(-row=>1,-column=>2); $but3 -> grid(-row=>2,-column=>2); MainLoop; sub calendar { %idx_for_mon = ( JAN=>1, FEB=>2, MAR=>3, APR=> 4, MAY=> 5, JUN=> 6, JUL=>7, AUG=>8, SEP=>9, OCT=>10, NOV=>11, DEC=>12 ); $input = '01-JAN-2013'; # Initial value for display $mw = MainWindow->new(); $mw->geometry( '200x80' ); $mw->resizable( 0, 0 ); $entry = $mw->DateEntry( -textvariable=>\$input, -width=>11, -parsecmd=>\&parse, -formatcmd=>\&format )->pack; $mw->Button( -text=>'Cancel', -command=>sub{ $mw->destroy; } )->pack( -side=>'right' ); $mw->Button( -text=>'OK', -command=>sub{ convert( $input ); } )->pack( -side=>'left' ); # called on dropdown with content of \$textvariable, must return ( $yr, $mon, $day ) sub parse { ( $day, $mon, $yr ) = split '-', $_[0]; return ( $yr, $idx_for_mon{$mon}, $day ); } # called on user selection with ($yr, $mon, $day), must return formatted string sub format { ( $yr, $mon, $day ) = @_; %mon_for_idx = reverse %idx_for_mon; return sprintf( "%02d-%s-%2d", $day, $mon_for_idx{ $mon }, $yr ); } # perform the conversion to epoch seconds when the corresponding button is pressed sub convert { ( $input) = @_; ( $yr, $mon, $day ) = parse( $input ); $output = "$day-$mon-$yr"; return $output; } }