Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Array of buttons

by GayathriBalu (Initiate)
on Oct 22, 2014 at 11:41 UTC ( #1104672=perlquestion: print w/replies, xml ) Need Help??

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

hi all, i want to create an array of buttons and handle them when clicked. in my code the last button in the array is handled even if any other button is clicked. pls help. thanks

my @buttons; for my $i(0..5){ push @buttons, $mw->Button(-text => $i, -command => sub{ print "pressed $i\n"; # or use the widget: print "pressed ", $buttons[$i]->cget('-text'), "\n"; })->pack; }

Replies are listed 'Best First'.
Re: Array of buttons
by choroba (Archbishop) on Oct 22, 2014 at 11:55 UTC
    What GUI are you using? Works correctly for me in Tk.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Array of buttons
by ww (Archbishop) on Oct 22, 2014 at 13:42 UTC

    Using Win7's CLI, prints the graphic as indicated, and prints "pressed n" to the CLI (NOT to the TK $mw) when a numbered button is clicked upon.

    YMMV if using xwindows or similar but my *nix boxen are comatose right now.

    ++$anecdote ne $data

Re: Array of buttons
by glenn (Scribe) on Oct 22, 2014 at 13:53 UTC
    Yes, a 'print' will go to STDOUT. So what are you trying to accomplish?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1104672]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-05-28 23:09 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.