in reply to print the values of the selected check buttons
What does the documentation say?
What do the examples say?
What is @Buttons used for?
What does push( my @Values, do? What is inside of @Values? What is @Values used for? What is the purpose of the my?
What are is inside of @Selected;?
If you can answer these questions you can have your answer
#!/usr/bin/perl -- ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END" -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" use strict; use warnings; use Path::Tiny qw/ path /; use Data::Dump qw/ dd pp /; use Tk; Main( @ARGV ); exit( 0 ); sub Main { my( $file ) = @_; my @lines = ( $file ? path( $file )->lines_raw : 1 .. 4 ); s/\s+$// for @lines; GoTk( \@lines ); } sub GoTk { my( $albums ) = @_; my $mw = MainWindow->new; $mw->title( scalar( @$albums ) . ' Albums ' ); my @buttons; for my $album ( @$albums ) { push @buttons, $mw->Checkbutton( -text => "$album", -onvalue => 1, -offvalue => 0, )->pack( -side => 'top', -anchor => 'nw' ); } my $GetAlbumsButtons = $mw->Button( -text => "Get Albums", -command => [ \&get_albums, $mw, \@buttons, ], )->pack( -side => 'bottom', -anchor => 's' ); #~ use Tk::WidgetDump; $mw->WidgetDump; MainLoop; } ## end sub GoTk sub get_albums { my( $mw, $buttons ) = @_; #~ my @buttons = grep { $_->isa("Tk::Checkbutton") } $mw->children + ; my $pp = ""; for my $but ( @$buttons ) { my $var = $but->cget( -variable ); my $text = $but->cget( -text ); my $val = $$var; #~ my $val = $but->{Value}; dd( { checked => $val, text => $text } ); $pp .= "\n" . pp( { checked => $val, text => $text } ); } $mw->MsgBox( -title => "Selected Albums", -message => $pp, -type => "okcancel", )->Show; } ## end sub get_albums __END__
|
|---|