Hmm, I guess $date stands out a little better with additional sleep and a whack on the side of the head. :-)

Perhaps my problem was that I was reading the docs and only perceived the get method for fishing data out, and didn't think about invoking get via a separate button that could access the object via a parameter. But then that's why, at midnight, I asked. :-)

That same fascination with $cd->get and my fear of MainLoop blinded me to the fact that $date was available to pass as a return value after the MainLoop finished. I was puzzling with If "get" is how you get the date, how does "get" continue to work after the MainLoop?

So, thanks to your example, the following obeys use strict and gets the value from the calendar by wrapping the appropriate code in a subroutine. Thanks!

(Interestingly in this example, the $date supplied to the ff_get sub remains frozen at 05/05/2005 since it doesn't update dynamically as global. But the value that the user clicks on the calendar, as obtained via $cd_or->get, does since the lookup method gets to fire later, i.e. when the 'Get' button is pushed.)

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ChooseDate; my ( $new_date ) = get_date(); print "ndt is '$new_date'\n"; sub get_date { #sets date thru the textvariable #my $date = '2006/6/6'; my $date = '4/1/2007'; #2006/6/6'; my $mw = new MainWindow; $mw->geometry('200x50'); $mw->fontCreate( 'big', -family=>'courier', -weight=>'bold', -size=>int(-18*18/14) ); my $cd = $mw->ChooseDate( -language =>'English', # changed from 'Italian' -font =>'big', # the label font -bg=>'lightsteelblue', #the label bg -textvariable=>\$date, -arrowcolor => 'black', -arrowactivecolor=>'yellow', -datecolor=> 'blue', -dateformat => 1, -orthodox => 1, # changed from '0' -daysofweekcolor=>'lightgreen', -highlightcolor=> 'pink', -linecolor=> 'green', -yearcolor=> 'black', #-command=>sub{print "$date\n"}, # quiesced this.... )->pack(-fill=>'x', -expand=>1); my $cdcan = $cd->Subwidget('canvas'); $cdcan->configure(-bg=>'black'); # bg of weekdays bar my $cdtop = $cd->Subwidget('toplevel'); $cdtop->configure(-bg=>'black'); # outline of popup # sets the date thru set $cd->set( y=>2005, m=>5, d=>5 ); my $get_button = $mw->Button( -text=>'Get', -command=>[\&ff_get, $date, $cd ], )->pack(); MainLoop; return ( $date ); } sub ff_get { my ( $date, $cd_or ) = @_; # $cd_or is an object reference print "getting....\n"; print "$date\n\n"; #print "$_[0]\n\n"; print "getting1....\n"; print $cd_or->get,"\n\n"; #print $_[1]->get,"\n\n"; }

In reply to Re^4: Perl / Tk Calendar - advice please. by ff
in thread Perl / Tk Calendar - advice please. by jdtoronto

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.