Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

Line up Calendar

by mikasue (Friar)
on Nov 21, 2006 at 18:00 UTC ( #585318=perlquestion: print w/ replies, xml ) Need Help??
mikasue has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

In a program of mine, I'm trying to show a calendar for the current month. I am using Date::Calc Calendar function and while it prints to the screen nicely formatted, my tk label looks ugly.

use strict; use warnings; use Date::Calc qw/Calendar/; use Tk; my $MW = MainWindow->new(); $MW->geometry('300x200+50+50'); my $cal = Date::Calc::Calendar(2006,11); $MW->Label(-text=>$cal)->grid(); MainLoop;

Can anyone please advice me on how to line up this calendar?

Comment on Line up Calendar
Download Code
Re: Line up Calendar
by webfiend (Vicar) on Nov 21, 2006 at 18:18 UTC

    I'd look for existing solutions before rolling my own, since calendars are hard to get "just so". How about starting with Tk::Month?

    Update for posterity: Don't use Tk::Month. It has limited functionality and doesn't appear to have been maintained in some time. I gave the above advice based on an optimistic appraisal of the module after doing a quick search on CPAN and looking at the docs.

    Update: It works fine. Just keep it simple:

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Month; my $mw = MainWindow->new(); my $month = "November"; my $year = "2006"; my $m = $mw->Month( -printformat => '%a %e', -includeall => 0, -month => $month, -year => $year, -command => sub { my ($ym, $wd) = @_; my ($month, $year) = split( /\s+/ , $ym ); my ($wday, $date) = split( /\s+/ , $wd->[0] ); print "$wday, $month $date $year\n"; }, ); $m->pack; MainLoop;
      How do you use Tk::Month? This code just hangs...
      use strict; use warnings; use Tk; use Tk::Month; my $MW = MainWindow->new(); $MW->geometry('300x200+50+50'); my $m = $MW->Month( -month => 'November', -year => '2006', -title => '%b %y', -command => \&press, -printformat => '%e', -navigation => [0|1], -includeall => [0|1], -showall => [0|1], -first => [0|1|2|3|4|5|6], )->pack(); MainLoop;

        I don't get hanging, but I don't get a nice calendar either. It looks like Tk::Month is old, unmaintained, and broken. Too bad, because it looks like it might have been just the thing.

        Back to the drawing board.

        You want to show a calendar, but what purpose does it serve? Are you trying to do anything with the calendar, or just show the dates of the current month as a reference point?

        Update: I was throwing too much code at it. Tk::Month works fine if I keep it simple. See my original reply to this thread for details.

Re: Line up Calendar
by davidrw (Prior) on Nov 21, 2006 at 19:48 UTC
    Looks like by default it's using a non-fixed width font and centering the text ... this will fixed both issues:
    $MW->Label(-text=>$cal, -font => "courier 10 bold", -justify=>"left")- +>grid();
      thanks!

      I like this option because I can use the tk::label options to change how it looks

      However, tk:Month is something to consider for another purpose.

      Thanks for all replys!

Re: Line up Calendar
by GrandFather (Cardinal) on Nov 21, 2006 at 20:17 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://585318]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-04-23 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (553 votes), past polls