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

Hi monks! I'm playing about with an option menu in tk. It is a simple menu, where you select a month name (January, Feburary etc) and the number of the month is displayed (01,02 etc). That bit's ok. What I'd like to do is set the option menu to default to the current month. I can get the variable to default to a value, but I can't seem to get the option menu itself to change. Any ideas?
#!/usr/bin/perl -w use Tk; use Strict; $mw = MainWindow->new(-title=>"Option Menu"); my $month; #$month='August'; #None of these seem to work $month='08'; #$month=8; my $start_month_field=$mw->Optionmenu( -variable => \$month)->pack; $start_month_field->addOptions([January=>'01'],[Feburary=>'02'],[March +=>'03'],[April=>'04'],[May=>'05'],[June=>'06'], [July=>'07'],[August=>'08'],[September=>'09'],[October=>'10'], +[November=>'11'],[December=>'12']); my $label=>$mw->Label(-textvariable=>\$month)->pack(); MainLoop();
Thanks

Replies are listed 'Best First'.
Re: Tk Optionmenu default value
by PodMaster (Abbot) on Jul 11, 2003 at 09:14 UTC
    http://perltk.org/ptknews/18675.htm
    $start_month_field->setOption("March");
    `perldoc -f localtime'.

    perlTk may not have every single option documented, but it's easy to use perltk.org to search for info or just look at the perl source, or at the tcl/tk documentation.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thanks very much PodMaster! That works nicely, and if I change it to $start_month_field->setOption(March=>'03'); it sets the variable to the correct number. Thanks again