Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-05-18 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?