1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | use Tk; use Tk:ateEntry; use Time:ocal; %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-APR-2004'; # Initial value for display $mw = MainWindow->new(); $mw->geometry( '200x80' ); $mw->resizable( 0, 0 ); $label = $mw->Label( -text=>'' )->pack; $entry = $mw->DateEntry( -textvariable=>\$input, -width=>11, -parsecmd=>\&parse, -formatcmd=>\&format )->pack; $mw->Button( -text=>'Quit', -command=>sub{ exit } )->pack( -side=>'right' ); $mw->Button( -text=>'Convert', -command=>sub{ convert( $input, $label ) } )->pack( -side=>'left' ); MainLoop; # called on dropdown with content of \$textvariable, must return ( $yr, $mon, $day ) sub parse { my ( $day, $mon, $yr ) = split '-', $_[0]; return ( $yr, $idx_for_mon{$mon}, $day ); } # called on user selection with ($yr, $mon, $day), must return formatted string sub format { my ( $yr, $mon, $day ) = @_; my %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 button is pressed sub convert { my ( $input, $label ) = @_; my ( $yr, $mon, $day ) = parse( $input ); my $output = "Epoch seconds: " . timelocal( 0, 0, 0, $day, $mon-1, $yr-1900 ); $label->configure( -text => $output ); } |
1 2 3 4 5 6 7 8 9 10 11 | use Tk; use Tk:athEntry; use Cwd; $path = cwd(); $mw = MainWindow->new(); $mw->geometry( '300x80' ); $mw->resizable( 0, 0 ); $mw->athEntry( -textvariable=>\$path )->pack; $mw->Label( -textvariable=>\$path, -foreground=>'blue' )->pack; $mw->Button( -text=>'Quit', -command=>sub{ exit } )->pack; MainLoop; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |