Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I believe its related to scope of variable and i'm a newbie to perl, so cant figure it out..

As a newbie, you should be using

use warnings; use strict;
Also, you should not be using a second mainwindow to pop your calendar, use a toplevel window instead. I'm not going to fix your messed up code, but to get the date back into your entry, use a -textvariable in the entry options.

This will return the output of the calendar to the second entry widget, but I would not say the rest of the code is OK, but it works,

#!/usr/bin/perl use warnings; #use strict; 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 $ent1_var = 1111111; my $ent = $frame->Entry(-textvariable => \$ent1_var)->pack(- +side=>'left'); my $frame1 = $tl->Frame()->pack(-side=>'right'); my $lab1 = $frame1->Label(-text=>"To ")->pack(-side=>'right +'); my $ent2_var = 2222222; my $ent1 = $frame1->Entry(-textvariable => \$ent2_var)->pack +(-side=>'right'); my $textarea = $tl -> Frame(); my $text = $textarea -> Text(-width=>170 , -height=>30, -font=> "Couri +er 9 bold", -wrap =>'none'); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $t +ext]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $t +ext]); $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\n"; #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 => $p +ush_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 formatt +ed 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 butto +n is pressed sub convert { ( $input) = @_; ( $yr, $mon, $day ) = parse( $input ); print "convert\n"; $output = "$day-$mon-$yr"; $ent2_var = $output; #return $output; } }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Tk Date::Entry by zentara
in thread Tk Date::Entry by reaper9187

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2014-07-26 14:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (178 votes), past polls