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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.